benchmark
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
total = ( || 1_000) strings = Dir["spec/**/*_spec.rb"] floats = strings {|s| s + rand } Benchmark do |x| x("loop") do times = 0 while times < total floats {|s| s } times += 1 end end x("primitive") do times = 0 while times < total floats {|s| s s } times += 1 end end x("ffi s + s") do times = 0 while times < total floats {|s| s + s } times += 1 end end x("ffi P::F.add s, s") do times = 0 while times < total floats {|s| Platform s, s } times += 1 end end x("ffi F.add s, s") do F = Platform times = 0 while times < total floats {|s| F s, s } times += 1 end end end |
run
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
euler:rubinius brian$ rm ffi; TOTAL=10_000 shotgun/rubinius ffi Rehearsal ----------------------------------------------------- loop 5.363105 0.000000 5.363105 ( 5.363095) primitive 7.478554 0.000000 7.478554 ( 7.478548) ffi s + s 28.856437 0.000000 28.856437 ( 28.856417) ffi P s, s 10.915453 0.000000 10.915453 ( 10.915431) ffi F s, s 10.432356 0.000000 10.432356 ( 10.432340) ------------------------------------------- total: 63.045905sec user system total real loop 5.216899 0.000000 5.216899 ( 5.216879) primitive 8.549649 0.000000 8.549649 ( 8.549653) ffi s + s 28.714589 0.000000 28.714589 ( 28.714583) ffi P s, s 10.994805 0.000000 10.994805 ( 10.994813) ffi F s, s 10.541753 0.000000 10.541753 ( 10.541763) |
Pastie