Skip to content

Instantly share code, notes, and snippets.

@matthewd
Created May 27, 2011 14:05
Show Gist options
  • Select an option

  • Save matthewd/995312 to your computer and use it in GitHub Desktop.

Select an option

Save matthewd/995312 to your computer and use it in GitHub Desktop.
tango:src/rbx[hydra]% rbx -Xgc.large_object=5000 reverse.rb 4900
user system total real
Reversing string 4900 long 3.644228 0.004000 3.648228 ( 3.751245)
tango:src/rbx[hydra]% rbx -Xgc.large_object=2700 reverse.rb 2665
user system total real
Reversing string 2665 long 13.372836 0.028001 13.400837 ( 13.470050)
require 'benchmark'
def do_reverse(r)
s = 'a' * r
1000000.times { s.reverse }
end
r = ARGV.shift.to_i
Benchmark.bm do |b|
b.report "Reversing string #{r} long" do
do_reverse(r)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment