Skip to content

Instantly share code, notes, and snippets.

@NagayamaRyoga

NagayamaRyoga/mkbench.bash Secret

Last active Sep 11, 2019
Embed
What would you like to do?
#!/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