Skip to content

Instantly share code, notes, and snippets.

@lemire
Created May 8, 2023 19:33
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 lemire/dcdc6e3fd4b3e593359bbe024bb6a313 to your computer and use it in GitHub Desktop.
Save lemire/dcdc6e3fd4b3e593359bbe024bb6a313 to your computer and use it in GitHub Desktop.
for each benchmark for TypeBitSet
/* performance benchmark */
/* This script expects node.js */
"use strict";
const { TypedFastBitSet, SparseTypedFastBitSet } = require("../lib");
const Benchmark = require("benchmark");
const os = require("os");
const smallgap = 3;
const largegap = 210;
const N = 1024 * 1024;
function ForEachBench() {
console.log("starting forEach benchmark");
const tb = new TypedFastBitSet();
const stb = new SparseTypedFastBitSet();
const s = new Set();
for (let i = 0; i < N; i++) {
tb.add(smallgap * i + 5);
stb.add(smallgap * i + 5);
}
const suite = new Benchmark.Suite();
// add tests
const ms = suite
.add("TypedFastBitSet", function () {
let card = 0;
const inc = function () {
card++;
};
tb.forEach(inc);
return card;
})
.add("SparseTypedFastBitSet", function () {
let card = 0;
const inc = function () {
card++;
};
stb.forEach(inc);
return card;
})
// add listeners
.on("cycle", function (event) {
console.log(String(event.target));
})
// run async
.run({ async: false });
}
const main = function () {
console.log(
"Platform: " + process.platform + " " + os.release() + " " + process.arch
);
console.log(os.cpus()[0]["model"]);
console.log(
"Node version " +
process.versions.node +
", v8 version " +
process.versions.v8
);
console.log("");
ForEachBench();
console.log("");
};
if (require.main === module) {
main();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment