Skip to content

Instantly share code, notes, and snippets.

@NagayamaRyoga
Last active September 11, 2019 02:38
Show Gist options
  • Save NagayamaRyoga/d482938f3a03c4556d297bb09c03e1fa to your computer and use it in GitHub Desktop.
Save NagayamaRyoga/d482938f3a03c4556d297bb09c03e1fa to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
(echo "# coding: utf-8"; cat ./ruby/{benchmark/*.rb,basictest/test.rb}) > bench.rb
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