source: trip-planner-front/node_modules/hdr-histogram-js/src/bench/histogram-percentile.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.0 KB
Line 
1import b from "benny";
2import { build } from "../index";
3import { initWebAssembly } from "../wasm";
4initWebAssembly().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 get value at percentile",
11 b.add(
12 "Int32Histogram",
13 () => {
14 const histogram = build({
15 bitBucketSize: 32
16 });
17 for (let index = 0; index < 1024; index++) {
18 histogram.recordValueWithCount(randomInteger(), randomInteger(100));
19 }
20 return () => {
21 histogram.getValueAtPercentile(99);
22 };
23 },
24 options
25 ),
26
27 b.add(
28 "WASM 32B Histogram",
29 () => {
30 const histogram = build({
31 bitBucketSize: 32,
32 useWebAssembly: true
33 });
34 for (let index = 0; index < 1024; index++) {
35 histogram.recordValueWithCount(randomInteger(), randomInteger(100));
36 }
37 return () => {
38 histogram.getValueAtPercentile(99);
39 };
40 },
41 options
42 ),
43 b.add(
44 "Packed Histogram",
45 () => {
46 const histogram = build({
47 bitBucketSize: "packed"
48 });
49 for (let index = 0; index < 1024; index++) {
50 histogram.recordValueWithCount(randomInteger(), randomInteger(100));
51 }
52 return () => {
53 histogram.getValueAtPercentile(99);
54 };
55 },
56 options
57 ),
58 b.add(
59 "WASM Packed Histogram",
60 () => {
61 const histogram = build({
62 bitBucketSize: "packed",
63 useWebAssembly: true
64 });
65 for (let index = 0; index < 1024; index++) {
66 histogram.recordValueWithCount(randomInteger(), randomInteger(100));
67 }
68 return () => {
69 histogram.getValueAtPercentile(99);
70 };
71 },
72 options
73 ),
74
75 b.complete(),
76 b.save({ file: "percentile", format: "chart.html" })
77 );
78});
Note: See TracBrowser for help on using the repository browser.