Last active
October 9, 2016 12:23
-
-
Save thomascharbonnel/f023ca137f2b2b7021cbe2d580485cd4 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' | |
require 'fds' | |
Benchmark.bm(30) do |bm| | |
bm.report('Using FDS::UnorderedSet') do | |
set = FDS::UnorderedSet.new | |
10_000.times do | |
set << rand | |
set.find_index(42) | |
end | |
end | |
bm.report('Using default Ruby Set') do | |
set = Set.new | |
10_000.times do | |
set << rand | |
set.find_index(42) | |
end | |
end | |
end | |
# user system total real | |
# Using FDS::UnorderedSet 0.010000 0.000000 0.010000 ( 0.006958) | |
# Using default Ruby Set 4.030000 0.010000 4.040000 ( 4.059034) |
@rringler, true. I just updated the gist using recommended gem Benchmark. The result should be closer to reality. 😄
One should note that the slow operation for Ruby Set here is Enumerable#find_index. Insertion is about 15% slower on FDS implementation (because of hash values initialization).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minor nit: but the execution time of
puts "Test 0: #{end_test_0 - start}"
is getting added to the second set's benchmark. Might be better to have have to separate start variables just to keep things apples to apples.