source: trip-planner-front/node_modules/hdr-histogram-js/src/bench/histogram-decoding.ts@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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