source: trip-planner-front/node_modules/hdr-histogram-js/src/bench/histogram-distribution.ts@ 188ee53

Last change on this file since 188ee53 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: 100 };
8
9 b.suite(
10 "Histogram percentile distribution",
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.outputPercentileDistribution();
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.outputPercentileDistribution();
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.outputPercentileDistribution();
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.outputPercentileDistribution();
70 };
71 },
72 options
73 ),
74
75 b.complete(),
76 b.save({ file: "distribution", format: "chart.html" })
77 );
78});
Note: See TracBrowser for help on using the repository browser.