histogram-percentile.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const benny_1 = require("benny");
  4. const index_1 = require("../index");
  5. const wasm_1 = require("../wasm");
  6. wasm_1.initWebAssembly().then(() => {
  7. const randomInteger = (max = Number.MAX_SAFE_INTEGER) => Math.floor(Math.random() * max);
  8. const options = { initCount: 1000 };
  9. benny_1.default.suite("Histogram get value at percentile", benny_1.default.add("Int32Histogram", () => {
  10. const histogram = index_1.build({
  11. bitBucketSize: 32
  12. });
  13. for (let index = 0; index < 1024; index++) {
  14. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  15. }
  16. return () => {
  17. histogram.getValueAtPercentile(99);
  18. };
  19. }, options), benny_1.default.add("WASM 32B Histogram", () => {
  20. const histogram = index_1.build({
  21. bitBucketSize: 32,
  22. useWebAssembly: true
  23. });
  24. for (let index = 0; index < 1024; index++) {
  25. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  26. }
  27. return () => {
  28. histogram.getValueAtPercentile(99);
  29. };
  30. }, options), benny_1.default.add("Packed Histogram", () => {
  31. const histogram = index_1.build({
  32. bitBucketSize: "packed"
  33. });
  34. for (let index = 0; index < 1024; index++) {
  35. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  36. }
  37. return () => {
  38. histogram.getValueAtPercentile(99);
  39. };
  40. }, options), benny_1.default.add("WASM Packed Histogram", () => {
  41. const histogram = index_1.build({
  42. bitBucketSize: "packed",
  43. useWebAssembly: true
  44. });
  45. for (let index = 0; index < 1024; index++) {
  46. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  47. }
  48. return () => {
  49. histogram.getValueAtPercentile(99);
  50. };
  51. }, options), benny_1.default.complete(), benny_1.default.save({ file: "percentile", format: "chart.html" }));
  52. });
  53. //# sourceMappingURL=histogram-percentile.js.map