Created
April 26, 2012 20:44
-
-
Save takai/2503006 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
require 'benchmark' | |
require 'set' | |
source = 100000.times.map { rand(100) } | |
n = 100 | |
Benchmark.bm(5) do |x| | |
x.report('uniq') do n.times { source.uniq } end | |
x.report('uniq!') do n.times { source.uniq! } end | |
x.report('set') do n.times { Set.new(source) } end | |
x.report('hash') do n.times { source.each_with_object(Hash.new) {|i, h| h[i] }.keys } end | |
end |
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
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0] | |
user system total real | |
uniq 0.770000 0.000000 0.770000 ( 0.777292) | |
uniq! 0.010000 0.000000 0.010000 ( 0.011109) | |
set 0.010000 0.000000 0.010000 ( 0.003713) | |
hash 0.000000 0.000000 0.000000 ( 0.001277) |
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
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java] | |
user system total real | |
uniq 0.555000 0.000000 0.555000 ( 0.555000) | |
uniq! 0.015000 0.000000 0.015000 ( 0.015000) | |
set 0.208000 0.000000 0.208000 ( 0.208000) | |
hash 0.089000 0.000000 0.089000 ( 0.090000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment