histogram-add.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 add", benny_1.default.add("Int32Histogram", () => {
  10. const histogram = index_1.build();
  11. const histogram2 = index_1.build();
  12. for (let index = 0; index < 1024; index++) {
  13. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  14. histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
  15. }
  16. return () => {
  17. histogram.add(histogram2);
  18. };
  19. }, options), benny_1.default.add("WASM 32B Histogram", () => {
  20. const histogram = index_1.build({ useWebAssembly: true });
  21. const histogram2 = index_1.build({ useWebAssembly: true });
  22. for (let index = 0; index < 1024; index++) {
  23. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  24. histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
  25. }
  26. return () => {
  27. histogram.add(histogram2);
  28. };
  29. }, options), benny_1.default.add("Packed Histogram", () => {
  30. const histogram = index_1.build({ bitBucketSize: "packed" });
  31. const histogram2 = index_1.build({ bitBucketSize: "packed" });
  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. }, options), benny_1.default.add("WASM Packed Histogram", () => {
  40. const histogram = index_1.build({
  41. bitBucketSize: "packed",
  42. useWebAssembly: true
  43. });
  44. const histogram2 = index_1.build({
  45. bitBucketSize: "packed",
  46. useWebAssembly: true
  47. });
  48. for (let index = 0; index < 1024; index++) {
  49. histogram.recordValueWithCount(randomInteger(), randomInteger(100));
  50. histogram2.recordValueWithCount(randomInteger(), randomInteger(100));
  51. }
  52. return () => {
  53. histogram.add(histogram2);
  54. };
  55. }, options), benny_1.default.complete(), benny_1.default.save({ file: "add", format: "chart.html" }));
  56. });
  57. //# sourceMappingURL=histogram-add.js.map