pearson-hashing 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmark/collisions.rb +31 -0
- data/benchmark/speed.rb +24 -0
- data/lib/pearson-hashing.rb +1 -1
- data/lib/pearson-hashing/version.rb +1 -1
- data/spec/lib/pearson_hashing_spec.rb +1 -1
- metadata +3 -1
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/pearson-hashing', __FILE__)
|
4
|
+
|
5
|
+
SIZE = 100_000
|
6
|
+
|
7
|
+
def benchmark(name, &block)
|
8
|
+
puts "#{name}.."
|
9
|
+
hashes = {}
|
10
|
+
SIZE.times do |i|
|
11
|
+
hash = block.call(i.to_s)
|
12
|
+
hashes[hash] ||= 0
|
13
|
+
hashes[hash] = hashes[hash] + 1
|
14
|
+
end
|
15
|
+
|
16
|
+
# analysis
|
17
|
+
collisions = hashes.inject(0){|coll,v| coll += (v[1]-1); coll}
|
18
|
+
puts " => #{collisions} collisions per #{SIZE} (#{collisions/SIZE.to_f}%)"
|
19
|
+
end
|
20
|
+
|
21
|
+
benchmark 'PearsonHashing#digest8' do |str|
|
22
|
+
PearsonHashing.digest8 str
|
23
|
+
end
|
24
|
+
|
25
|
+
benchmark 'PearsonHashing#digest16' do |str|
|
26
|
+
PearsonHashing.digest16 str
|
27
|
+
end
|
28
|
+
|
29
|
+
benchmark 'String#hash' do |str|
|
30
|
+
str.hash
|
31
|
+
end
|
data/benchmark/speed.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'benchmark'
|
4
|
+
require File.expand_path('../../lib/pearson-hashing', __FILE__)
|
5
|
+
|
6
|
+
Benchmark.bm do |b|
|
7
|
+
b.report 'PearsonHashing#digest8' do
|
8
|
+
100_000.times do |i|
|
9
|
+
PearsonHashing.digest8 i.to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
b.report 'PearsonHashing#digest16' do
|
14
|
+
100_000.times do |i|
|
15
|
+
PearsonHashing.digest16 i.to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
b.report 'String#hash' do
|
20
|
+
100_000.times do |i|
|
21
|
+
i.to_s.hash
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/pearson-hashing.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pearson-hashing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,6 +23,8 @@ files:
|
|
23
23
|
- MIT-LICENSE
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
|
+
- benchmark/collisions.rb
|
27
|
+
- benchmark/speed.rb
|
26
28
|
- lib/pearson-hashing.rb
|
27
29
|
- lib/pearson-hashing/version.rb
|
28
30
|
- pearson-hashing.gemspec
|