Created
July 10, 2010 23:48
-
-
Save bhuga/471141 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
I hacked up methodmissing's promise to rename it to ExtPromise. Then I edited the benchmark program like so: | |
require "benchmark" | |
require "ext/promise/promise" | |
require "promise" | |
TESTS = 1000 | |
Benchmark.bmbm do |results| | |
# Picked inspect instead of undefined, as the pure-ruby promise will raise an | |
# exception on undefined instead of return the promise value | |
results.report("Promise") { TESTS.times { Promise.new{ 1 }.inspect } } #.undefined } } | |
results.report("ExtPromise") { TESTS.times { ExtPromise.new{ 1 }.inspect } } #.undefined } } | |
results.report("Promise#==") { TESTS.times { Promise.new{ 1 } == 1 } } | |
results.report("ExtPromise#==") { TESTS.times { ExtPromise.new{ 1 } == 1 } } | |
results.report("Promise#object_id") { TESTS.times { Promise.new{ 1 }.object_id } } | |
results.report("ExtPromise#object_id") { TESTS.times { ExtPromise.new{ 1 }.object_id } } | |
results.report("Promise#__send__") { TESTS.times { Promise.new{ 1 }.__send__ :object_id } } | |
results.report("ExtPromise#__send__") { TESTS.times { ExtPromise.new{ 1 }.__send__ :object_id } } | |
results.report("Promise (blocking)") { TESTS.times { Promise.new{ IO.read(__FILE__) }.inspect } } #.undefined } } | |
results.report("ExtPromise (blocking)") { TESTS.times { ExtPromise.new{ IO.read(__FILE__) }.inspect } } #.undefined } } | |
results.report("Promise#== (blocking)") { TESTS.times { Promise.new{ IO.read(__FILE__) } == 1 } } | |
results.report("ExtPromise#== (blocking)") { TESTS.times { ExtPromise.new{ IO.read(__FILE__) } == 1 } } | |
results.report("Promise#object_id (blocking)") { TESTS.times { Promise.new{ IO.read(__FILE__) }.object_id } } | |
results.report("ExtPromise#object_id (blocking)") { TESTS.times { ExtPromise.new{ IO.read(__FILE__) }.object_id } } | |
results.report("Promise#__send__ (blocking)") { TESTS.times { Promise.new{ IO.read(__FILE__) }.__send__ :object_id } } | |
results.report("ExtPromise#__send__ (blocking)") { TESTS.times { ExtPromise.new{ IO.read(__FILE__) }.__send__ :object_id } } | |
end | |
The results: | |
ben:ext-promise ben$ rake bench | |
(in /Users/ben/Repos/ext-promise) | |
/opt/local/bin/ruby bench/promise.rb | |
Rehearsal ------------------------------------------------------------------- | |
Promise 0.010000 0.000000 0.010000 ( 0.008493) | |
ExtPromise 0.000000 0.000000 0.000000 ( 0.009953) | |
Promise#== 0.010000 0.000000 0.010000 ( 0.007722) | |
ExtPromise#== 0.010000 0.010000 0.020000 ( 0.011172) | |
Promise#object_id 0.010000 0.000000 0.010000 ( 0.008627) | |
ExtPromise#object_id 0.010000 0.000000 0.010000 ( 0.011326) | |
Promise#__send__ 0.010000 0.000000 0.010000 ( 0.008789) | |
ExtPromise#__send__ 0.030000 0.000000 0.030000 ( 0.042061) | |
Promise (blocking) 0.120000 0.020000 0.140000 ( 0.136777) | |
ExtPromise (blocking) 0.040000 0.060000 0.100000 ( 0.102843) | |
Promise#== (blocking) 0.030000 0.020000 0.050000 ( 0.048383) | |
ExtPromise#== (blocking) 0.060000 0.050000 0.110000 ( 0.119921) | |
Promise#object_id (blocking) 0.030000 0.030000 0.060000 ( 0.046365) | |
ExtPromise#object_id (blocking) 0.060000 0.050000 0.110000 ( 0.119973) | |
Promise#__send__ (blocking) 0.020000 0.020000 0.040000 ( 0.049523) | |
ExtPromise#__send__ (blocking) 0.050000 0.050000 0.100000 ( 0.106921) | |
---------------------------------------------------------- total: 0.810000sec | |
user system total real | |
Promise 0.010000 0.000000 0.010000 ( 0.008081) | |
ExtPromise 0.010000 0.000000 0.010000 ( 0.010787) | |
Promise#== 0.010000 0.000000 0.010000 ( 0.007979) | |
ExtPromise#== 0.010000 0.000000 0.010000 ( 0.012617) | |
Promise#object_id 0.010000 0.000000 0.010000 ( 0.007502) | |
ExtPromise#object_id 0.010000 0.000000 0.010000 ( 0.009332) | |
Promise#__send__ 0.010000 0.000000 0.010000 ( 0.007801) | |
ExtPromise#__send__ 0.010000 0.000000 0.010000 ( 0.010346) | |
Promise (blocking) 0.110000 0.020000 0.130000 ( 0.134745) | |
ExtPromise (blocking) 0.050000 0.050000 0.100000 ( 0.103976) | |
Promise#== (blocking) 0.020000 0.020000 0.040000 ( 0.046742) | |
ExtPromise#== (blocking) 0.040000 0.060000 0.100000 ( 0.102794) | |
Promise#object_id (blocking) 0.030000 0.020000 0.050000 ( 0.045789) | |
ExtPromise#object_id (blocking) 0.050000 0.050000 0.100000 ( 0.103494) | |
Promise#__send__ (blocking) 0.020000 0.030000 0.050000 ( 0.046701) | |
ExtPromise#__send__ (blocking) 0.050000 0.050000 0.100000 ( 0.106211) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment