Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active June 5, 2018 01:44
Show Gist options
  • Save havenwood/b526607da727b044b28ecca7c27589ef to your computer and use it in GitHub Desktop.
Save havenwood/b526607da727b044b28ecca7c27589ef to your computer and use it in GitHub Desktop.
Pure Ruby SipHash Benchmark https://github.com/havenwood/digest-sip_hash
~ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
~ ruby pure_ruby_siphash_bench.rb
Warming up --------------------------------------
empty SipHash13 6.052k i/100ms
10 Xs SipHash13 4.674k i/100ms
100 Xs SipHash13 1.601k i/100ms
empty SipHash24 4.329k i/100ms
10 Xs SipHash24 3.214k i/100ms
100 Xs SipHash24 925.000 i/100ms
Calculating -------------------------------------
empty SipHash13 59.717k (± 3.3%) i/s - 302.600k in 5.072798s
10 Xs SipHash13 45.807k (± 2.9%) i/s - 229.026k in 5.004055s
100 Xs SipHash13 16.207k (± 2.8%) i/s - 81.651k in 5.042130s
empty SipHash24 43.877k (± 2.9%) i/s - 220.779k in 5.036028s
10 Xs SipHash24 32.947k (± 2.5%) i/s - 167.128k in 5.075810s
100 Xs SipHash24 9.270k (± 3.0%) i/s - 47.175k in 5.093661s
Comparison:
empty SipHash13: 59717.3 i/s
10 Xs SipHash13: 45807.3 i/s - 1.30x slower
empty SipHash24: 43877.5 i/s - 1.36x slower
10 Xs SipHash24: 32947.1 i/s - 1.81x slower
100 Xs SipHash13: 16206.8 i/s - 3.68x slower
100 Xs SipHash24: 9270.2 i/s - 6.44x slower
~ ruby -v
jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 GraalVM 1.0.0-rc1 25.71-b01-internal-jvmci-0.42 on 1.8.0_161-b12 +jit [darwin-x86_64]
~ ruby -Xcompile.invokedynamic pure_ruby_siphash_bench.rb
Warming up --------------------------------------
empty SipHash13 233.000 i/100ms
10 Xs SipHash13 606.000 i/100ms
100 Xs SipHash13 369.000 i/100ms
empty SipHash24 3.772k i/100ms
10 Xs SipHash24 4.516k i/100ms
100 Xs SipHash24 1.281k i/100ms
Calculating -------------------------------------
empty SipHash13 99.372k (±13.3%) i/s - 479.747k in 4.981876s
10 Xs SipHash13 65.528k (±14.4%) i/s - 318.756k in 5.001283s
100 Xs SipHash13 19.303k (± 8.4%) i/s - 95.940k in 5.010926s
empty SipHash24 75.075k (± 2.6%) i/s - 377.200k in 5.027815s
10 Xs SipHash24 50.671k (± 3.2%) i/s - 257.412k in 5.085317s
100 Xs SipHash24 13.610k (± 3.1%) i/s - 69.174k in 5.087514s
Comparison:
empty SipHash13: 99371.8 i/s
empty SipHash24: 75075.1 i/s - 1.32x slower
10 Xs SipHash13: 65527.6 i/s - 1.52x slower
10 Xs SipHash24: 50670.6 i/s - 1.96x slower
100 Xs SipHash13: 19303.0 i/s - 5.15x slower
100 Xs SipHash24: 13610.0 i/s - 7.30x slower
~ ruby -v
jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 10.0.1+10 on 10.0.1+10 +jit [darwin-x86_64]
~ ruby pure_ruby_siphash_bench.rb
Warming up --------------------------------------
empty SipHash13 2.428k i/100ms
10 Xs SipHash13 3.234k i/100ms
100 Xs SipHash13 1.138k i/100ms
empty SipHash24 3.931k i/100ms
10 Xs SipHash24 2.747k i/100ms
100 Xs SipHash24 779.000 i/100ms
Calculating -------------------------------------
empty SipHash13 56.182k (± 3.9%) i/s - 281.648k in 5.021042s
10 Xs SipHash13 37.170k (± 3.4%) i/s - 187.572k in 5.052734s
100 Xs SipHash13 11.723k (± 3.5%) i/s - 59.176k in 5.054298s
empty SipHash24 41.247k (± 2.5%) i/s - 208.343k in 5.054371s
10 Xs SipHash24 28.328k (± 3.0%) i/s - 142.844k in 5.047403s
100 Xs SipHash24 7.873k (± 2.5%) i/s - 39.729k in 5.049377s
Comparison:
empty SipHash13: 56182.4 i/s
empty SipHash24: 41247.1 i/s - 1.36x slower
10 Xs SipHash13: 37169.5 i/s - 1.51x slower
10 Xs SipHash24: 28328.1 i/s - 1.98x slower
100 Xs SipHash13: 11723.1 i/s - 4.79x slower
100 Xs SipHash24: 7873.2 i/s - 7.14x slower
~ ruby -v
truffleruby 1.0.0-rc1, like ruby 2.3.7 <native build with Graal> [x86_64-darwin]
~ ruby pure_ruby_siphash_bench.rb
Warming up --------------------------------------
empty SipHash13 712.000 i/100ms
10 Xs SipHash13 657.000 i/100ms
100 Xs SipHash13 424.000 i/100ms
empty SipHash24 667.000 i/100ms
10 Xs SipHash24 1.269k i/100ms
100 Xs SipHash24 479.000 i/100ms
Calculating -------------------------------------
empty SipHash13 100.615k (±20.3%) i/s - 422.928k in 4.995740s
10 Xs SipHash13 78.784k (±20.5%) i/s - 335.727k in 4.997685s
100 Xs SipHash13 22.986k (±22.1%) i/s - 102.608k in 5.011680s
empty SipHash24 63.457k (±21.8%) i/s - 270.802k in 5.000982s
10 Xs SipHash24 46.650k (±25.4%) i/s - 203.040k in 5.026837s
100 Xs SipHash24 12.204k (±22.5%) i/s - 56.043k in 5.022917s
Comparison:
empty SipHash13: 100615.1 i/s
10 Xs SipHash13: 78783.7 i/s - same-ish: difference falls within error
empty SipHash24: 63457.2 i/s - 1.59x slower
10 Xs SipHash24: 46650.2 i/s - 2.16x slower
100 Xs SipHash13: 22985.5 i/s - 4.38x slower
100 Xs SipHash24: 12204.3 i/s - 8.24x slower
~ ruby -v
truffleruby 1.0.0-rc1, like ruby 2.3.7 <native build with Graal> [x86_64-darwin]
~ ruby pure_ruby_siphash_bench.rb
Warming up --------------------------------------
empty SipHash13[ruby] PERFORMANCE keyword arguments are not yet optimized
469.000 i/100ms
10 Xs SipHash13 224.000 i/100ms
100 Xs SipHash13 390.000 i/100ms
empty SipHash24 573.000 i/100ms
10 Xs SipHash24 1.319k i/100ms
100 Xs SipHash24 315.000 i/100ms
Calculating -------------------------------------
empty SipHash13 68.724k (±19.9%) i/s - 296.408k in 5.059658s
10 Xs SipHash13 54.533k (±17.0%) i/s - 228.256k in 4.996096s
100 Xs SipHash13 15.656k (±22.1%) i/s - 70.590k in 4.999878s
empty SipHash24 42.287k (±22.7%) i/s - 181.641k in 5.016792s
10 Xs SipHash24 30.387k (±25.1%) i/s - 135.857k in 5.018480s
100 Xs SipHash24 8.251k (±22.0%) i/s - 37.800k in 5.007420s
Comparison:
empty SipHash13: 68724.0 i/s
10 Xs SipHash13: 54533.4 i/s - same-ish: difference falls within error
empty SipHash24: 42286.6 i/s - 1.63x slower
10 Xs SipHash24: 30387.5 i/s - 2.26x slower
100 Xs SipHash13: 15655.9 i/s - 4.39x slower
100 Xs SipHash24: 8251.0 i/s - 8.33x slower
# frozen_string_literal: true
if defined? Truffle
class String
def unpack1 s
unpack(s).first
end
end
end
require 'benchmark/ips'
require 'digest/sip_hash'
Benchmark.ips do |x|
EMPTY = ''
TEN_X = 'X' * 10
HUNDRED_X = 'X' * 100
x.report('empty SipHash13') { Digest::SipHash.new(1, 3).hexdigest EMPTY }
x.report('10 Xs SipHash13') { Digest::SipHash.new(1, 3).hexdigest TEN_X }
x.report('100 Xs SipHash13') { Digest::SipHash.new(1, 3).hexdigest HUNDRED_X }
x.report('empty SipHash24') { Digest::SipHash.new(2, 4).hexdigest EMPTY }
x.report('10 Xs SipHash24') { Digest::SipHash.new(2, 4).hexdigest TEN_X }
x.report('100 Xs SipHash24') { Digest::SipHash.new(2, 4).hexdigest HUNDRED_X }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment