Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Oct 6, 2016

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.

@thomascharbonnel

This comment has been minimized.

Copy link
Owner Author

commented Oct 9, 2016

@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
You can’t perform that action at this time.