Skip to content

Instantly share code, notes, and snippets.

@headius

headius/bench.rb Secret

Forked from Papierkorb/bench.rb
Created November 19, 2015 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/7bea003b2747e24a2bd8 to your computer and use it in GitHub Desktop.
Save headius/7bea003b2747e24a2bd8 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'set'
#require 'rbtree'
range = (1..10_000)
array = range.to_a
set = SortedSet.new array
n = 1..1_000
puts "#{RUBY_ENGINE} #{RUBY_VERSION} #{RUBY_PLATFORM}"
5.times do
Benchmark.bm(9) do |x|
x.report("clone ary:"){ for i in n do; array.clone; end }
x.report("clone set:"){ for i in n do; set.clone; end }
x.report("array:"){ for i in n do; array.clone.delete rand range; end }
x.report("set:"){ for i in n do; set.clone.delete rand range; end }
end
end
ruby 2.2.2 x86_64-darwin14
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000344)
clone set: 5.450000 0.260000 5.710000 ( 5.708636)
array: 0.550000 0.030000 0.580000 ( 0.578321)
set: 5.560000 0.270000 5.830000 ( 5.838488)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000306)
clone set: 5.500000 0.250000 5.750000 ( 5.743380)
array: 0.500000 0.020000 0.520000 ( 0.530967)
set: 5.430000 0.260000 5.690000 ( 5.685856)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000310)
clone set: 5.460000 0.210000 5.670000 ( 5.668282)
array: 0.570000 0.010000 0.580000 ( 0.582949)
set: 5.500000 0.250000 5.750000 ( 5.744751)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000316)
clone set: 5.450000 0.230000 5.680000 ( 5.678672)
array: 0.530000 0.010000 0.540000 ( 0.536898)
set: 5.580000 0.260000 5.840000 ( 5.855124)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000310)
clone set: 5.540000 0.230000 5.770000 ( 5.765722)
array: 0.560000 0.010000 0.570000 ( 0.579307)
set: 5.480000 0.250000 5.730000 ( 5.731264)
jruby 2.2.2 java
user system total real
clone ary: 0.040000 0.010000 0.050000 ( 0.006449)
clone set: 1.380000 0.070000 1.450000 ( 0.726462)
array: 0.220000 0.000000 0.220000 ( 0.157413)
set: 0.740000 0.010000 0.750000 ( 0.595102)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000536)
clone set: 0.650000 0.010000 0.660000 ( 0.588222)
array: 0.130000 0.000000 0.130000 ( 0.115422)
set: 0.610000 0.000000 0.610000 ( 0.589447)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000446)
clone set: 0.600000 0.000000 0.600000 ( 0.580613)
array: 0.120000 0.000000 0.120000 ( 0.117128)
set: 0.780000 0.010000 0.790000 ( 0.630391)
user system total real
clone ary: 0.000000 0.000000 0.000000 ( 0.000383)
clone set: 0.630000 0.010000 0.640000 ( 0.587771)
array: 0.120000 0.000000 0.120000 ( 0.122875)
set: 0.580000 0.000000 0.580000 ( 0.576759)
user system total real
clone ary: 0.010000 0.000000 0.010000 ( 0.000390)
clone set: 0.600000 0.000000 0.600000 ( 0.593478)
array: 0.120000 0.000000 0.120000 ( 0.111606)
set: 0.610000 0.010000 0.620000 ( 0.580624)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment