[6a3a178] | 1 | import b from "benny";
|
---|
| 2 | import { build } from "../index";
|
---|
| 3 | import { initWebAssembly } from "../wasm";
|
---|
| 4 | initWebAssembly().then(() => {
|
---|
| 5 | const randomInteger = (max: number = Number.MAX_SAFE_INTEGER) =>
|
---|
| 6 | Math.floor(Math.random() * max);
|
---|
| 7 | const options = { initCount: 1000 };
|
---|
| 8 |
|
---|
| 9 | b.suite(
|
---|
| 10 | "Histogram add",
|
---|
| 11 | b.add(
|
---|
| 12 | "Int32Histogram",
|
---|
| 13 | () => {
|
---|
| 14 | const histogram = build();
|
---|
| 15 | const histogram2 = build();
|
---|
| 16 | for (let index = 0; index < 1024; index++) {
|
---|
| 17 | histogram.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 18 | histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 19 | }
|
---|
| 20 | return () => {
|
---|
| 21 | histogram.add(histogram2);
|
---|
| 22 | };
|
---|
| 23 | },
|
---|
| 24 | options
|
---|
| 25 | ),
|
---|
| 26 |
|
---|
| 27 | b.add(
|
---|
| 28 | "WASM 32B Histogram",
|
---|
| 29 | () => {
|
---|
| 30 | const histogram = build({ useWebAssembly: true });
|
---|
| 31 | const histogram2 = build({ useWebAssembly: true });
|
---|
| 32 | for (let index = 0; index < 1024; index++) {
|
---|
| 33 | histogram.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 34 | histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 35 | }
|
---|
| 36 | return () => {
|
---|
| 37 | histogram.add(histogram2);
|
---|
| 38 | };
|
---|
| 39 | },
|
---|
| 40 | options
|
---|
| 41 | ),
|
---|
| 42 | b.add(
|
---|
| 43 | "Packed Histogram",
|
---|
| 44 | () => {
|
---|
| 45 | const histogram = build({ bitBucketSize: "packed" });
|
---|
| 46 | const histogram2 = build({ bitBucketSize: "packed" });
|
---|
| 47 | for (let index = 0; index < 1024; index++) {
|
---|
| 48 | histogram.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 49 | histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 50 | }
|
---|
| 51 | return () => {
|
---|
| 52 | histogram.add(histogram2);
|
---|
| 53 | };
|
---|
| 54 | },
|
---|
| 55 | options
|
---|
| 56 | ),
|
---|
| 57 | b.add(
|
---|
| 58 | "WASM Packed Histogram",
|
---|
| 59 | () => {
|
---|
| 60 | const histogram = build({
|
---|
| 61 | bitBucketSize: "packed",
|
---|
| 62 | useWebAssembly: true
|
---|
| 63 | });
|
---|
| 64 | const histogram2 = build({
|
---|
| 65 | bitBucketSize: "packed",
|
---|
| 66 | useWebAssembly: true
|
---|
| 67 | });
|
---|
| 68 | for (let index = 0; index < 1024; index++) {
|
---|
| 69 | histogram.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 70 | histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
|
---|
| 71 | }
|
---|
| 72 | return () => {
|
---|
| 73 | histogram.add(histogram2);
|
---|
| 74 | };
|
---|
| 75 | },
|
---|
| 76 | options
|
---|
| 77 | ),
|
---|
| 78 |
|
---|
| 79 | b.complete(),
|
---|
| 80 | b.save({ file: "add", format: "chart.html" })
|
---|
| 81 | );
|
---|
| 82 | });
|
---|