Created
August 25, 2011 06:34
-
-
Save tenderlove/1170106 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
| class Sloppy | |
| def sloppy; @sloppy; end | |
| end | |
| class Tidy | |
| def initialize; @tidy = nil; end | |
| def tidy; @tidy; end | |
| end | |
| require 'benchmark' | |
| GC.disable | |
| tidy = Tidy.new | |
| sloppy = Sloppy.new | |
| [ 1, 10, 100, 10_000, 100_000_000 ].each do |n| | |
| puts "N: #{n}" | |
| Benchmark.bm(7) do |x| | |
| x.report('tidy') { | |
| n.times { tidy.tidy } | |
| } | |
| x.report('sloppy') { | |
| n.times { sloppy.sloppy } | |
| } | |
| end | |
| puts | |
| end | |
| __END__ | |
| [aaron@higgins git]$ ruby -v | |
| ruby 1.9.4dev (2011-08-25 trunk 33052) [x86_64-darwin11.1.0] | |
| [aaron@higgins git]$ ruby fuuu.rb | |
| N: 1 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000016) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000006) | |
| N: 10 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000008) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000009) | |
| N: 100 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000040) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000039) | |
| N: 10000 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.003054) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.003969) | |
| N: 100000000 | |
| user system total real | |
| tidy 29.880000 0.030000 29.910000 ( 30.232715) | |
| sloppy 35.030000 0.040000 35.070000 ( 35.505067) | |
| [aaron@higgins git]$ ruby -v | |
| ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] | |
| [aaron@higgins git]$ ruby fuuu.rb | |
| N: 1 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000239) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000007) | |
| N: 10 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000012) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000010) | |
| N: 100 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000177) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000172) | |
| N: 10000 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.003899) | |
| sloppy 0.010000 0.000000 0.010000 ( 0.004534) | |
| N: 100000000 | |
| user system total real | |
| tidy 40.210000 0.050000 40.260000 ( 41.566687) | |
| sloppy 40.110000 0.050000 40.160000 ( 40.921818) | |
| [aaron@higgins git]$ ruby -v | |
| jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java] | |
| [aaron@higgins git]$ ruby fuuu.rb | |
| fuuu.rb:1 warning: GC.disable does nothing on JRuby | |
| N: 1 | |
| user system total real | |
| tidy 0.084000 0.000000 0.084000 ( 0.017000) | |
| sloppy 0.002000 0.000000 0.002000 ( 0.002000) | |
| N: 10 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000000) | |
| sloppy 0.000000 0.000000 0.000000 ( 0.000000) | |
| N: 100 | |
| user system total real | |
| tidy 0.000000 0.000000 0.000000 ( 0.000000) | |
| sloppy 0.001000 0.000000 0.001000 ( 0.001000) | |
| N: 10000 | |
| user system total real | |
| tidy 0.078000 0.000000 0.078000 ( 0.078000) | |
| sloppy 0.051000 0.000000 0.051000 ( 0.051000) | |
| N: 100000000 | |
| user system total real | |
| tidy 8.361000 0.000000 8.361000 ( 8.362000) | |
| sloppy 8.997000 0.000000 8.997000 ( 8.997000) | |
| [aaron@higgins git]$ rbx -v | |
| rubinius 1.2.5dev (1.8.7 3790ba50 yyyy-mm-dd JI) [x86_64-apple-darwin11.1.0] | |
| [aaron@higgins git]$ rbx fuuu.rb | |
| N: 1 | |
| user system total real | |
| tidy 0.000181 0.000012 0.000193 ( 0.000026) | |
| sloppy 0.000020 0.000003 0.000023 ( 0.000018) | |
| N: 10 | |
| user system total real | |
| tidy 0.000013 0.000009 0.000022 ( 0.000012) | |
| sloppy 0.000013 0.000002 0.000015 ( 0.000011) | |
| N: 100 | |
| user system total real | |
| tidy 0.000044 0.000008 0.000052 ( 0.000106) | |
| sloppy 0.000037 0.000002 0.000039 ( 0.000182) | |
| N: 10000 | |
| user system total real | |
| tidy 0.002764 0.000013 0.002777 ( 0.002826) | |
| sloppy 0.008063 0.000101 0.008164 ( 0.006082) | |
| N: 100000000 | |
| user system total real | |
| tidy 13.934830 0.017758 13.952588 ( 14.151206) | |
| sloppy 9.565299 0.005134 9.570433 ( 9.594408) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment