Skip to content

Instantly share code, notes, and snippets.

@kyledecot
Last active October 3, 2016 14:20
Show Gist options
  • Save kyledecot/a05982af3ae2d718795e435c0aa2f36e to your computer and use it in GitHub Desktop.
Save kyledecot/a05982af3ae2d718795e435c0aa2f36e to your computer and use it in GitHub Desktop.
require "benchmark"
require "securerandom"
Benchmark.bm do |bm|
15.times do |t|
n = t * 10_000
a = [].tap do |array|
n.times { array << SecureRandom.uuid }
end
bm.report("#{n} uniq") { a.uniq }
end
end
user system total real
0 uniq 0.000000 0.000000 0.000000 ( 0.000004)
10000 uniq 0.010000 0.000000 0.010000 ( 0.005481)
20000 uniq 0.010000 0.000000 0.010000 ( 0.013604)
30000 uniq 0.020000 0.000000 0.020000 ( 0.022462)
40000 uniq 0.040000 0.000000 0.040000 ( 0.035382)
50000 uniq 0.040000 0.000000 0.040000 ( 0.045865)
60000 uniq 0.050000 0.000000 0.050000 ( 0.048567)
70000 uniq 0.060000 0.000000 0.060000 ( 0.059995)
80000 uniq 0.080000 0.000000 0.080000 ( 0.078481)
90000 uniq 0.100000 0.000000 0.100000 ( 0.107666)
100000 uniq 0.090000 0.000000 0.090000 ( 0.094583)
110000 uniq 0.120000 0.000000 0.120000 ( 0.129481)
120000 uniq 0.140000 0.010000 0.150000 ( 0.143909)
130000 uniq 0.150000 0.010000 0.160000 ( 0.153648)
140000 uniq 0.150000 0.000000 0.150000 ( 0.145950)
ruby benchmark.rb 7.20s user 0.13s system 99% cpu 7.341 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment