funny-falcon / murmurhash3-ruby Goto Github PK
View Code? Open in Web Editor NEWRuby implementation of noncriptographic hash Murmur3 (both native and pure ruby)
License: MIT License
Ruby implementation of noncriptographic hash Murmur3 (both native and pure ruby)
License: MIT License
Hi,
while version 0.1.6
has also the -java
version of the gem, the new 0.1.7
doesn't.
This make impossible to use on JRuby.
Please, could you publish also the 0.1.7-java
one?
As you can see in the following benchmark, joining (stringifying) the 4 ints that MurmurHash3 V128 returns is a HUGE slowdown:
$ ruby foo.rb
Calculating -------------------------------------
MD5 hexdigest 33983 i/100ms
SHA1 hexdigest 34126 i/100ms
SHA256 hexdigest 28005 i/100ms
MurmurHash3 61312 i/100ms
MurmurHash3+join 25005 i/100ms
-------------------------------------------------
MD5 hexdigest 602213.6 (±2.2%) i/s - 3024487 in 5.024776s
SHA1 hexdigest 606277.1 (±2.5%) i/s - 3037214 in 5.013147s
SHA256 hexdigest 446773.8 (±2.3%) i/s - 2240400 in 5.017521s
MurmurHash3 2058126.0 (±4.1%) i/s - 10300416 in 5.013492s
MurmurHash3+join 383117.5 (±1.7%) i/s - 1925385 in 5.027135s
Here's the code:
require 'digest/sha1'
require 'digest/sha2'
require 'digest/md5'
require 'murmurhash3'
require 'benchmark/ips'
str = 'The quick brown fox jumps over the 123 dog'
Benchmark.ips do |x|
x.report("MD5 hexdigest") { ::Digest::MD5.hexdigest str }
x.report("SHA1 hexdigest") { ::Digest::SHA1.hexdigest str }
x.report("SHA256 hexdigest") { ::Digest::SHA256.hexdigest str }
x.report("MurmurHash3") { ::MurmurHash3::V128.str_hash str }
x.report("MurmurHash3+join") { ::MurmurHash3::V128.str_hash(str).join }
end
Wouldn't it be nice to have a native method like ::MurmurHash3::V128.str_hash_str(str, base = 10)
that takes a string and returns a string:
::MurmurHash3::V128.str_hash_str(str) #=> 499258781-3237023466-187941375-3296492016
::MurmurHash3::V128.str_hash_str(str, 16) #=> 1dc2159d-c0f10eea-b33c1ff-c47c79f0
::MurmurHash3::V128.str_hash_str(str, 36) #=> 898ujh-1hj8nai-33w8hr-1iin9io
Then you could use that directly in string IDs.
I just installed murmurhash3 with gem install murmurhash3
on my computer (tested on mac and linux., intel-based)
I receive the following message:
require 'murmurhash3'
# Attention: used pure ruby version of MurmurHash3
# => true
I checked the gem location on my computer. The native.so
has been created at ./lib/native.so
The reason for this error is, that it cannot require the file murmurhash3/native
:
require 'murmurhash3/native'
# LoadError: cannot load such file -- murmurhash3/native
# from /Users/myuser/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'
I was able to fix this error and also the warning above by moving the native.so
file to ./lib/murmurhash3/native.so
require 'murmurhash3'
# => true
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.