-
-
Save Paxa/321be47319327e5e7058 to your computer and use it in GitHub Desktop.
test.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
res = 1 | |
for i in (0..10).to_a | |
res *= i | |
end | |
res >= 100 |
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
ruby -v | |
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0] | |
laptop harddrive 5400 rpm | |
CPU Code 2duo 2.0Ghz | |
~/Sites/boost% ruby ./test1.rb | |
user system total real | |
standart eval 0.470000 0.010000 0.480000 ( 0.503260) | |
compiled eval 0.040000 0.000000 0.040000 ( 0.043089) | |
iseq eval 0.470000 0.000000 0.470000 ( 0.494641) | |
standart load 0.940000 0.470000 1.410000 ( 1.480897) | |
compiled load 0.830000 0.340000 1.170000 ( 1.236602) |
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' | |
code = File.open('./code.rb', 'r', &:read) | |
is = RubyVM::InstructionSequence.compile(code) | |
Benchmark.bm do |x| | |
x.report("standart eval") do | |
10_000.times { eval(code) } | |
end | |
x.report("compiled eval") do | |
10_000.times { is.eval } | |
end | |
x.report("iseq eval ") do | |
10_000.times { RubyVM::InstructionSequence.compile(code).eval } | |
end | |
filename = File.expand_path(File.join(File.dirname(__FILE__), 'code.rb')) | |
x.report("standart load") do | |
10_000.times { load filename } | |
end | |
x.report("compiled load") do | |
10_000.times do | |
RubyVM::InstructionSequence.compile_file(filename).eval | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment