Skip to content

Instantly share code, notes, and snippets.

@colinsurprenant
Last active December 14, 2015 05:29
Show Gist options
  • Save colinsurprenant/5036162 to your computer and use it in GitHub Desktop.
Save colinsurprenant/5036162 to your computer and use it in GitHub Desktop.
quick bench of MRI Ruby 1.9.3-p392 vs JRuby 1.7.3 computing hashes. MD5 & SHA-1 are part of the standard libraries. native FNV is in pure Ruby. ffi and c-ext FNV are in C. Just ran these while refactoring for ffi-compiler & JRuby 1.7.3 my https://github.com/colinsurprenant/bloombroom gem.

JRuby 1.7.3

benchmarking for 1000000 iterations
                         user     system      total        real
MD5:                 1.400000   0.040000   1.440000 (  1.007000)
SHA-1:               1.450000   0.010000   1.460000 (  1.043000)
native FNV A 32:     8.620000   0.050000   8.670000 (  8.197000)
native FNV A 64:    11.950000   0.050000  12.000000 ( 11.717000)
native FNV B 32:     3.290000   0.010000   3.300000 (  3.036000)
native FNV B 64:    11.670000   0.060000  11.730000 ( 11.286000)
ffi FNV 32:          0.670000   0.030000   0.700000 (  0.512000)
ffi FNV 64:          0.470000   0.030000   0.500000 (  0.409000)

MD5:                   993049 ops/s
SHA-1:                 958773 ops/s
native FNV A 32:       121996 ops/s
native FNV A 64:        85346 ops/s
native FNV B 32:       329381 ops/s
native FNV B 64:        88605 ops/s
ffi FNV 32:           1953125 ops/s
ffi FNV 64:           2444987 ops/s

MRI Ruby 1.9.3-p392

benchmarking for 1000000 iterations
                         user     system      total        real
MD5:                 1.350000   0.000000   1.350000 (  1.353281)
SHA-1:               1.360000   0.000000   1.360000 (  1.360537)
native FNV A 32:    21.750000   0.090000  21.840000 ( 21.828011)
native FNV A 64:    27.580000   0.310000  27.890000 ( 27.973790)
native FNV B 32:     4.320000   0.000000   4.320000 (  4.328807)
native FNV B 64:    23.520000   0.030000  23.550000 ( 23.556782)
ffi FNV 32:          0.660000   0.000000   0.660000 (  0.657626)
ffi FNV 64:          0.720000   0.000000   0.720000 (  0.725043)
c-ext FNV 32:        0.220000   0.000000   0.220000 (  0.218276)
c-ext FNV 64:        0.290000   0.000000   0.290000 (  0.292134)

MD5:                   738945 ops/s
SHA-1:                 735004 ops/s
native FNV A 32:        45813 ops/s
native FNV A 64:        35748 ops/s
native FNV B 32:       231011 ops/s
native FNV B 64:        42451 ops/s
ffi FNV 32:           1520621 ops/s
ffi FNV 64:           1379228 ops/s
c-ext FNV 32:         4581360 ops/s
c-ext FNV 64:         3423086 ops/s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment