Last active
September 25, 2018 09:53
-
-
Save cimi/7094b68ab476fd4635bc5e6df39b95c6 to your computer and use it in GitHub Desktop.
Benchmark modified version of murmurhash3js with multi-byte character code handling against original
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Benchmark from "benchmark"; | |
import benchmarks from "beautify-benchmark"; | |
import polyfill from "text-encoding"; | |
import murmurhash3jsOriginal from "murmurhash3js"; | |
import murmurhash3jsModified from "@cimi/murmurhash3js"; | |
test.only( | |
"benchmark example", | |
() => { | |
const suite = new Benchmark.Suite(); | |
const originalHash = murmurhash3jsOriginal.x86.hash128; | |
const modifiedHash = murmurhash3jsModified.x86.hash128; | |
const getBytes = (() => { | |
const textEncoder = new polyfill.TextEncoder(); // ? new TextEncoder() : undefined; | |
return str => textEncoder.encode(str); | |
})(); | |
const str = "My hovercraft is full of eels."; | |
const multibyte = "My 🚀 is full of 🐍."; | |
suite | |
.add("original hash applied to ascii string", function() { | |
originalHash(str); | |
}) | |
.add("modified hash applied to ascii string", function () { | |
modifiedHash(getBytes(str)); | |
}) | |
.add("original hash applied to multibyte string", function() { | |
originalHash(multibyte); | |
}) | |
.add("modified hash applied to multibyte string", function () { | |
modifiedHash(getBytes(multibyte)); | |
}) | |
.on("cycle", function(event) { | |
benchmarks.add(event.target); | |
}) | |
.on("complete", function() { | |
benchmarks.log(); | |
}) | |
.run(); | |
}, | |
60000 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment