Skip to content

Instantly share code, notes, and snippets.

@cimi
Last active September 25, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cimi/7094b68ab476fd4635bc5e6df39b95c6 to your computer and use it in GitHub Desktop.
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
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