import b from "benny"; import { build } from "../index"; import { initWebAssembly } from "../wasm"; initWebAssembly().then(() => { const randomInteger = (max: number = Number.MAX_SAFE_INTEGER) => Math.floor(Math.random() * max); const options = { initCount: 1000 }; b.suite( "Histogram get value at percentile", b.add( "Int32Histogram", () => { const histogram = build({ bitBucketSize: 32 }); for (let index = 0; index < 1024; index++) { histogram.recordValueWithCount(randomInteger(), randomInteger(100)); } return () => { histogram.getValueAtPercentile(99); }; }, options ), b.add( "WASM 32B Histogram", () => { const histogram = build({ bitBucketSize: 32, useWebAssembly: true }); for (let index = 0; index < 1024; index++) { histogram.recordValueWithCount(randomInteger(), randomInteger(100)); } return () => { histogram.getValueAtPercentile(99); }; }, options ), b.add( "Packed Histogram", () => { const histogram = build({ bitBucketSize: "packed" }); for (let index = 0; index < 1024; index++) { histogram.recordValueWithCount(randomInteger(), randomInteger(100)); } return () => { histogram.getValueAtPercentile(99); }; }, options ), b.add( "WASM Packed Histogram", () => { const histogram = build({ bitBucketSize: "packed", useWebAssembly: true }); for (let index = 0; index < 1024; index++) { histogram.recordValueWithCount(randomInteger(), randomInteger(100)); } return () => { histogram.getValueAtPercentile(99); }; }, options ), b.complete(), b.save({ file: "percentile", format: "chart.html" }) ); });