-
-
Save NagayamaRyoga/d482938f3a03c4556d297bb09c03e1fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
(echo "# coding: utf-8"; cat ./ruby/{benchmark/*.rb,basictest/test.rb}) > bench.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
Filename = './bench.rb' | |
TmpFile = './tmp.bc' | |
iseq = RubyVM::InstructionSequence.compile_file(Filename) | |
encoded_iseq = iseq.to_binary | |
File.write(TmpFile, encoded_iseq) | |
puts "size: #{encoded_iseq.length}B" | |
N = 1000 | |
Benchmark.bm do |x| | |
x.report("load_from_binary") do || | |
N.times { | |
RubyVM::InstructionSequence.load_from_binary(encoded_iseq) | |
} | |
end | |
x.report("File.read + load_from_binary") do || | |
N.times { | |
RubyVM::InstructionSequence.load_from_binary(File.read(TmpFile)) | |
} | |
end | |
x.report("compile_file") do || | |
N.times { | |
RubyVM::InstructionSequence.compile_file(Filename) | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment