data-structure-typed 1.41.6 → 1.41.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +11 -11
  3. package/benchmark/report.html +11 -11
  4. package/benchmark/report.json +111 -111
  5. package/dist/cjs/src/data-structures/graph/abstract-graph.js +5 -5
  6. package/dist/cjs/src/data-structures/graph/abstract-graph.js.map +1 -1
  7. package/dist/mjs/src/data-structures/graph/abstract-graph.js +5 -5
  8. package/dist/umd/data-structure-typed.min.js +1 -1
  9. package/dist/umd/data-structure-typed.min.js.map +1 -1
  10. package/package.json +5 -5
  11. package/src/data-structures/graph/abstract-graph.ts +6 -6
  12. package/test/config.ts +1 -0
  13. package/test/integration/avl-tree.test.ts +110 -0
  14. package/test/integration/bst.test.ts +385 -0
  15. package/test/integration/heap.test.js +16 -0
  16. package/test/integration/index.html +51 -0
  17. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +36 -0
  18. package/test/performance/data-structures/binary-tree/binary-index-tree.test.ts +0 -0
  19. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +45 -0
  20. package/test/performance/data-structures/binary-tree/bst.test.ts +36 -0
  21. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  22. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +0 -0
  23. package/test/performance/data-structures/binary-tree/segment-tree.test.ts +0 -0
  24. package/test/performance/data-structures/binary-tree/tree-multiset.test.ts +0 -0
  25. package/test/performance/data-structures/graph/abstract-graph.test.ts +0 -0
  26. package/test/performance/data-structures/graph/directed-graph.test.ts +49 -0
  27. package/test/performance/data-structures/graph/map-graph.test.ts +0 -0
  28. package/test/performance/data-structures/graph/overall.test.ts +0 -0
  29. package/test/performance/data-structures/graph/undirected-graph.test.ts +0 -0
  30. package/test/performance/data-structures/hash/coordinate-map.test.ts +0 -0
  31. package/test/performance/data-structures/hash/coordinate-set.test.ts +0 -0
  32. package/test/performance/data-structures/hash/hash-map.test.ts +0 -0
  33. package/test/performance/data-structures/hash/hash-table.test.ts +0 -0
  34. package/test/performance/data-structures/heap/heap.test.ts +30 -0
  35. package/test/performance/data-structures/heap/max-heap.test.ts +0 -0
  36. package/test/performance/data-structures/heap/min-heap.test.ts +0 -0
  37. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +40 -0
  38. package/test/performance/data-structures/linked-list/linked-list.test.ts +0 -0
  39. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +34 -0
  40. package/test/performance/data-structures/linked-list/skip-linked-list.test.ts +0 -0
  41. package/test/performance/data-structures/linked-list/skip-list.test.ts +0 -0
  42. package/test/performance/data-structures/matrix/matrix.test.ts +0 -0
  43. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  44. package/test/performance/data-structures/matrix/navigator.test.ts +0 -0
  45. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  46. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +19 -0
  47. package/test/performance/data-structures/priority-queue/min-priority-queue.test.ts +0 -0
  48. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +0 -0
  49. package/test/performance/data-structures/queue/deque.test.ts +21 -0
  50. package/test/performance/data-structures/queue/queue.test.ts +25 -0
  51. package/test/performance/data-structures/stack/stack.test.ts +0 -0
  52. package/test/performance/data-structures/tree/tree.test.ts +0 -0
  53. package/test/performance/data-structures/trie/trie.test.ts +22 -0
  54. package/test/performance/reportor.ts +186 -0
  55. package/test/performance/types/index.ts +1 -0
  56. package/test/performance/types/reportor.ts +3 -0
  57. package/test/types/index.ts +1 -0
  58. package/test/types/utils/big-o.ts +1 -0
  59. package/test/types/utils/index.ts +2 -0
  60. package/test/types/utils/json2html.ts +1 -0
  61. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +269 -0
  62. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +320 -0
  63. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +486 -0
  64. package/test/unit/data-structures/binary-tree/bst.test.ts +840 -0
  65. package/test/unit/data-structures/binary-tree/overall.test.ts +66 -0
  66. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +435 -0
  67. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +50 -0
  68. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +542 -0
  69. package/test/unit/data-structures/graph/abstract-graph.test.ts +100 -0
  70. package/test/unit/data-structures/graph/directed-graph.test.ts +564 -0
  71. package/test/unit/data-structures/graph/map-graph.test.ts +126 -0
  72. package/test/unit/data-structures/graph/overall.test.ts +49 -0
  73. package/test/unit/data-structures/graph/salty-edges.json +1 -0
  74. package/test/unit/data-structures/graph/salty-vertexes.json +1 -0
  75. package/test/unit/data-structures/graph/undirected-graph.test.ts +168 -0
  76. package/test/unit/data-structures/hash/coordinate-map.test.ts +74 -0
  77. package/test/unit/data-structures/hash/coordinate-set.test.ts +66 -0
  78. package/test/unit/data-structures/hash/hash-map.test.ts +103 -0
  79. package/test/unit/data-structures/hash/hash-table.test.ts +186 -0
  80. package/test/unit/data-structures/heap/heap.test.ts +254 -0
  81. package/test/unit/data-structures/heap/max-heap.test.ts +52 -0
  82. package/test/unit/data-structures/heap/min-heap.test.ts +52 -0
  83. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +400 -0
  84. package/test/unit/data-structures/linked-list/linked-list.test.ts +8 -0
  85. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +474 -0
  86. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
  87. package/test/unit/data-structures/linked-list/skip-list.test.ts +86 -0
  88. package/test/unit/data-structures/matrix/matrix.test.ts +54 -0
  89. package/test/unit/data-structures/matrix/matrix2d.test.ts +345 -0
  90. package/test/unit/data-structures/matrix/navigator.test.ts +244 -0
  91. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  92. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +73 -0
  93. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +63 -0
  94. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +53 -0
  95. package/test/unit/data-structures/queue/deque.test.ts +410 -0
  96. package/test/unit/data-structures/queue/queue.test.ts +207 -0
  97. package/test/unit/data-structures/stack/stack.test.ts +67 -0
  98. package/test/unit/data-structures/tree/tree.test.ts +39 -0
  99. package/test/unit/data-structures/trie/trie.test.ts +825 -0
  100. package/test/utils/array.ts +5514 -0
  101. package/test/utils/big-o.ts +207 -0
  102. package/test/utils/console.ts +31 -0
  103. package/test/utils/index.ts +7 -0
  104. package/test/utils/is.ts +56 -0
  105. package/test/utils/json2html.ts +322 -0
  106. package/test/utils/number.ts +13 -0
  107. package/test/utils/string.ts +1 -0
@@ -0,0 +1,45 @@
1
+ import {BinaryTree} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {getRandomIntArray, magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const biTree = new BinaryTree<number>();
7
+ const {N_LOG_N} = magnitude;
8
+ const arr = getRandomIntArray(N_LOG_N, 0, N_LOG_N, true);
9
+
10
+ suite
11
+ .add(`${N_LOG_N} add randomly`, () => {
12
+ biTree.clear();
13
+ for (let i = 0; i < arr.length; i++) {
14
+ biTree.add(arr[i]);
15
+ }
16
+ })
17
+ .add(`${N_LOG_N} add & delete randomly`, () => {
18
+ biTree.clear();
19
+ for (let i = 0; i < arr.length; i++) {
20
+ biTree.add(arr[i]);
21
+ }
22
+ for (let i = 0; i < arr.length; i++) {
23
+ biTree.delete(arr[i]);
24
+ }
25
+ })
26
+ .add(`${N_LOG_N} addMany`, () => {
27
+ biTree.clear();
28
+ biTree.addMany(arr);
29
+ })
30
+ .add(`${N_LOG_N} get`, () => {
31
+ for (let i = 0; i < arr.length; i++) {
32
+ biTree.get(arr[i]);
33
+ }
34
+ })
35
+ .add(`${N_LOG_N} dfs`, () => {
36
+ for (let i = 0; i < N_LOG_N; i++) biTree.dfs();
37
+ })
38
+ .add(`${N_LOG_N} bfs`, () => {
39
+ for (let i = 0; i < N_LOG_N; i++) biTree.bfs();
40
+ })
41
+ .add(`${N_LOG_N} morris`, () => {
42
+ for (let i = 0; i < N_LOG_N; i++) biTree.morris(n => n, 'pre');
43
+ });
44
+
45
+ export {suite};
@@ -0,0 +1,36 @@
1
+ import {BST} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {getRandomIntArray, magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const bst = new BST<number>();
7
+ const {N_LOG_N} = magnitude;
8
+ const arr = getRandomIntArray(N_LOG_N, 0, N_LOG_N, true);
9
+
10
+ suite
11
+ .add(`${N_LOG_N} add randomly`, () => {
12
+ bst.clear();
13
+ for (let i = 0; i < arr.length; i++) {
14
+ bst.add(arr[i]);
15
+ }
16
+ })
17
+ .add(`${N_LOG_N} add & delete randomly`, () => {
18
+ bst.clear();
19
+ for (let i = 0; i < arr.length; i++) {
20
+ bst.add(arr[i]);
21
+ }
22
+ for (let i = 0; i < arr.length; i++) {
23
+ bst.delete(arr[i]);
24
+ }
25
+ })
26
+ .add(`${N_LOG_N} addMany`, () => {
27
+ bst.clear();
28
+ bst.addMany(arr);
29
+ })
30
+ .add(`${N_LOG_N} get`, () => {
31
+ for (let i = 0; i < arr.length; i++) {
32
+ bst.get(arr[i]);
33
+ }
34
+ });
35
+
36
+ export {suite};
@@ -0,0 +1,49 @@
1
+ import {DirectedGraph} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {getRandomIndex, getRandomWords, magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {THOUSAND} = magnitude;
7
+ const graph = new DirectedGraph<number, number>();
8
+ const vertexes = getRandomWords(THOUSAND);
9
+
10
+ suite
11
+ .add(`${THOUSAND} addVertex`, () => {
12
+ for (const v of vertexes) {
13
+ graph.addVertex(v);
14
+ }
15
+ })
16
+ .add(`${THOUSAND} addEdge`, () => {
17
+ for (let i = 0; i < THOUSAND; i++) {
18
+ const v1 = vertexes[getRandomIndex(vertexes)];
19
+ const v2 = vertexes[getRandomIndex(vertexes)];
20
+ graph.addEdge(v1, v2);
21
+ }
22
+ })
23
+ .add(`${THOUSAND} getVertex`, () => {
24
+ for (let i = 0; i < THOUSAND; i++) {
25
+ graph.getVertex(vertexes[getRandomIndex(vertexes)]);
26
+ }
27
+ })
28
+ .add(`${THOUSAND} getEdge`, () => {
29
+ for (let i = 0; i < THOUSAND; i++) {
30
+ graph.getEdge(vertexes[getRandomIndex(vertexes)], vertexes[getRandomIndex(vertexes)]);
31
+ }
32
+ })
33
+ .add(`tarjan`, () => {
34
+ // for (let i = 0; i < THOUSAND; i++) {
35
+ graph.tarjan(true);
36
+ // }
37
+ })
38
+ .add(`tarjan all`, () => {
39
+ // for (let i = 0; i < THOUSAND; i++) {
40
+ graph.tarjan(true, true, true, true);
41
+ // }
42
+ })
43
+ .add(`topologicalSort`, () => {
44
+ // for (let i = 0; i < THOUSAND; i++) {
45
+ graph.topologicalSort('key');
46
+ // }
47
+ });
48
+
49
+ export {suite};
@@ -0,0 +1,30 @@
1
+ import {FibonacciHeap, Heap} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {N_LOG_N} = magnitude;
7
+
8
+ suite
9
+ .add(`${N_LOG_N} add & pop`, () => {
10
+ const heap = new Heap<number>({comparator: (a, b) => b - a});
11
+
12
+ for (let i = 0; i < N_LOG_N; i++) {
13
+ heap.add(i);
14
+ }
15
+
16
+ for (let i = 0; i < N_LOG_N; i++) {
17
+ heap.pop();
18
+ }
19
+ })
20
+ .add(`${N_LOG_N} fib add & pop`, () => {
21
+ const fbHeap = new FibonacciHeap<number>();
22
+ for (let i = 1; i <= N_LOG_N; i++) {
23
+ fbHeap.push(i);
24
+ }
25
+ for (let i = 1; i <= N_LOG_N; i++) {
26
+ fbHeap.pop();
27
+ }
28
+ });
29
+
30
+ export {suite};
@@ -0,0 +1,40 @@
1
+ import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {LINEAR, N_LOG_N} = magnitude;
7
+
8
+ suite
9
+ .add(`${LINEAR} unshift`, () => {
10
+ const list = new DoublyLinkedList<number>();
11
+
12
+ for (let i = 0; i < LINEAR; i++) {
13
+ list.unshift(i);
14
+ }
15
+ })
16
+ .add(`${LINEAR} unshift & shift`, () => {
17
+ const list = new DoublyLinkedList<number>();
18
+
19
+ for (let i = 0; i < LINEAR; i++) {
20
+ list.unshift(i);
21
+ }
22
+ for (let i = 0; i < LINEAR; i++) {
23
+ list.shift();
24
+ }
25
+ })
26
+ .add(`${N_LOG_N} insertBefore`, () => {
27
+ const doublyList = new DoublyLinkedList<number>();
28
+ let midNode: DoublyLinkedListNode | null = null;
29
+ const midIndex = Math.floor(N_LOG_N / 2);
30
+ for (let i = 0; i < N_LOG_N; i++) {
31
+ doublyList.push(i);
32
+ if (i === midIndex) {
33
+ midNode = doublyList.getNode(i);
34
+ } else if (i > midIndex && midNode) {
35
+ doublyList.insertBefore(midNode, i);
36
+ }
37
+ }
38
+ });
39
+
40
+ export {suite};
@@ -0,0 +1,34 @@
1
+ import {SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {N_LOG_N} = magnitude;
7
+
8
+ suite
9
+ .add(`${N_LOG_N} push & pop`, () => {
10
+ const list = new SinglyLinkedList<number>();
11
+
12
+ for (let i = 0; i < N_LOG_N; i++) {
13
+ list.push(i);
14
+ }
15
+
16
+ for (let i = 0; i < N_LOG_N; i++) {
17
+ list.pop();
18
+ }
19
+ })
20
+ .add(`${N_LOG_N} insertBefore`, () => {
21
+ const singlyList = new SinglyLinkedList<number>();
22
+ let midSinglyNode: SinglyLinkedListNode | null = null;
23
+ const midIndex = Math.floor(N_LOG_N / 2);
24
+ for (let i = 0; i < N_LOG_N; i++) {
25
+ singlyList.push(i);
26
+ if (i === midIndex) {
27
+ midSinglyNode = singlyList.getNode(i);
28
+ } else if (i > midIndex && midSinglyNode) {
29
+ singlyList.insertBefore(midSinglyNode.value, i);
30
+ }
31
+ }
32
+ });
33
+
34
+ export {suite};
@@ -0,0 +1,19 @@
1
+ import {MaxPriorityQueue} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {TEN_THOUSAND} = magnitude;
7
+
8
+ suite.add(`${TEN_THOUSAND} refill & poll`, () => {
9
+ const nodes = Array.from(
10
+ new Set<number>(Array.from(new Array(TEN_THOUSAND), () => Math.floor(Math.random() * TEN_THOUSAND * 100)))
11
+ );
12
+ const maxPQ = new MaxPriorityQueue<number>();
13
+ maxPQ.refill(nodes);
14
+ while (maxPQ.size > 0) {
15
+ maxPQ.poll();
16
+ }
17
+ });
18
+
19
+ export {suite};
@@ -0,0 +1,21 @@
1
+ import {Deque} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {magnitude} from '../../../utils';
4
+
5
+ export const suite = new Benchmark.Suite();
6
+ const {LINEAR} = magnitude;
7
+
8
+ suite
9
+ .add(`${LINEAR} push`, () => {
10
+ const deque = new Deque<number>();
11
+ for (let i = 0; i < LINEAR; i++) {
12
+ deque.push(i);
13
+ }
14
+ })
15
+ .add(`${LINEAR} shift`, () => {
16
+ const deque = new Deque<number>();
17
+ for (let i = 0; i < LINEAR; i++) {
18
+ deque.push(i);
19
+ deque.shift();
20
+ }
21
+ });
@@ -0,0 +1,25 @@
1
+ import {Queue} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {LINEAR} = magnitude;
7
+
8
+ suite
9
+ .add(`${LINEAR} push`, () => {
10
+ const queue = new Queue<number>();
11
+
12
+ for (let i = 0; i < LINEAR; i++) {
13
+ queue.push(i);
14
+ }
15
+ })
16
+ .add(`${LINEAR} push & shift`, () => {
17
+ const queue = new Queue<number>();
18
+
19
+ for (let i = 0; i < LINEAR; i++) {
20
+ queue.push(i);
21
+ queue.shift();
22
+ }
23
+ });
24
+
25
+ export {suite};
@@ -0,0 +1,22 @@
1
+ import {Trie} from '../../../../src';
2
+ import * as Benchmark from 'benchmark';
3
+ import {getRandomWords, magnitude} from '../../../utils';
4
+
5
+ const suite = new Benchmark.Suite();
6
+ const {HUNDRED_THOUSAND} = magnitude;
7
+ const trie = new Trie();
8
+ const randomWords = getRandomWords(HUNDRED_THOUSAND, false);
9
+
10
+ suite
11
+ .add(`${HUNDRED_THOUSAND} push`, () => {
12
+ for (let i = 0; i < randomWords.length; i++) {
13
+ trie.add(randomWords[i]);
14
+ }
15
+ })
16
+ .add(`${HUNDRED_THOUSAND} getWords`, () => {
17
+ for (let i = 0; i < randomWords.length; i++) {
18
+ trie.getWords(randomWords[i]);
19
+ }
20
+ });
21
+
22
+ export {suite};
@@ -0,0 +1,186 @@
1
+ import * as Benchmark from 'benchmark';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ import * as fastGlob from 'fast-glob';
5
+ import {Color, numberFix, render} from '../utils';
6
+ import {PerformanceTest} from './types';
7
+
8
+ const reportDistPath = 'benchmark';
9
+ const testDir = path.join(__dirname, 'data-structures');
10
+ const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
11
+
12
+ const report: {[key: string]: any} = {};
13
+
14
+ let completedCount = 0;
15
+
16
+ const performanceTests: PerformanceTest[] = [];
17
+ const {GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW} = Color;
18
+
19
+ testFiles.forEach((file: string) => {
20
+ const testName = path.basename(file, '.test.ts');
21
+ const testFunction = require(file);
22
+ const {suite} = testFunction;
23
+ if (suite) performanceTests.push({testName, suite, file});
24
+ });
25
+
26
+ const composeReport = () => {
27
+ if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, {recursive: true});
28
+
29
+ const filePath = path.join(reportDistPath, 'report.json');
30
+ const htmlFilePath = path.join(reportDistPath, 'report.html');
31
+ fs.writeFileSync(filePath, JSON.stringify(report, null, 2));
32
+ let html = `<!DOCTYPE html>
33
+ <html lang="en">
34
+ <head>
35
+ <meta charset="UTF-8">
36
+ <title>performance of data-structure-typed</title>
37
+ <style>
38
+ *{
39
+ box-sizing: border-box;
40
+ }
41
+ #json-to-html {
42
+ padding: 0 10px 20px;
43
+ }
44
+
45
+ .json-to-html-label {
46
+ font-size: 2rem;
47
+ margin: 2rem 0 0 3px;
48
+ }
49
+ .content table {
50
+ width: 100%;
51
+ table-layout: fixed;
52
+ border-collapse: collapse;
53
+ margin-top: 10px;
54
+ font-size: 16px;
55
+ }
56
+
57
+ .content table th,
58
+ .content table td {
59
+ padding: 8px 12px;
60
+ text-align: left;
61
+ border: 1px solid #ddd;
62
+ }
63
+
64
+ .content table th {
65
+ background-color: #f2f2f2;
66
+ font-weight: bold;
67
+ }
68
+
69
+ .content table tr:nth-child(odd) {
70
+ background-color: #ffffff;
71
+ }
72
+ </style>
73
+ </head>
74
+ <body>
75
+ <div id="json-to-html">`;
76
+ let htmlTables = '';
77
+ for (const r in report) {
78
+ if (report.hasOwnProperty(r)) {
79
+ htmlTables += render(report[r].testName, report[r].benchmarks, {
80
+ plainHtml: true,
81
+ '<>': 'table',
82
+ html: [
83
+ {
84
+ '<>': 'tr',
85
+ html: [
86
+ {'<>': 'td', html: '${name}'},
87
+ {'<>': 'td', html: '${periodMS}'},
88
+ {'<>': 'td', html: '${mean}'}
89
+ ]
90
+ }
91
+ ]
92
+ });
93
+ }
94
+ }
95
+ htmlTables += `
96
+
97
+ `;
98
+ html += htmlTables;
99
+ html += `</div>
100
+ </body>
101
+ </html>`;
102
+ replaceMarkdownContent(
103
+ '[//]: # (Start of Replace Section)', // Start tag
104
+ '[//]: # (End of Replace Section)', // end identifier
105
+ htmlTables // New content to be inserted
106
+ );
107
+ fs.writeFileSync(htmlFilePath, html);
108
+ console.log(`Performance ${BOLD}${GREEN}report${END} file generated`);
109
+ };
110
+ function replaceMarkdownContent(startMarker: string, endMarker: string, newText: string) {
111
+ const parentDirectory = path.resolve(__dirname, '../..'); // The path to the parent directory
112
+ const filePath = path.join(parentDirectory, 'README.md'); // Path to README.md file
113
+ fs.readFile(filePath, 'utf8', (err, data) => {
114
+ if (err) {
115
+ console.error(`Unable to read ${filePath}:`, err);
116
+ return;
117
+ }
118
+
119
+ // Find the start and end markers in the content
120
+ const startIndex = data.indexOf(startMarker);
121
+ const endIndex = data.indexOf(endMarker, startIndex + 1);
122
+
123
+ if (startIndex === -1 || endIndex === -1) {
124
+ console.error('Unable to find start or end marker');
125
+ return;
126
+ }
127
+
128
+ // Replace the old content with the new text
129
+ const updatedMarkdown =
130
+ data.slice(0, startIndex + startMarker.length) + '\n' + newText + data.slice(endIndex);
131
+
132
+ // Try writing the modified content back to the file
133
+ fs.writeFile(filePath, updatedMarkdown, 'utf8', (err) => {
134
+ if (err) {
135
+ console.error(`Unable to write to ${filePath}:`, err);
136
+ } else {
137
+ console.log(`The content has been successfully replaced in ${filePath}!`);
138
+ }
139
+ });
140
+ });
141
+ }
142
+
143
+ performanceTests.forEach(item => {
144
+ const {suite, testName, file} = item;
145
+ const relativeFilePath = path.relative(__dirname, file);
146
+ const directory = path.dirname(relativeFilePath);
147
+ const fileName = path.basename(relativeFilePath);
148
+ console.log(`${BG_YELLOW}Running in${END}: ${GRAY}${directory}/${END}${CYAN}${fileName}${END}`);
149
+
150
+ if (suite) {
151
+ let runTime = 0;
152
+ suite
153
+ .on('complete', function (this: Benchmark.Suite) {
154
+ completedCount++;
155
+ report[testName] = {};
156
+ report[testName].benchmarks = this.map((benchmark: Benchmark) => {
157
+ runTime += benchmark.times.elapsed;
158
+ return {
159
+ 'test name': benchmark.name,
160
+ 'time taken (ms)': numberFix(benchmark.times.period * 1000, 2),
161
+ 'executions per sec': numberFix(benchmark.hz, 2),
162
+ 'executed times': numberFix(benchmark.count, 0),
163
+ 'sample mean (secs)': numberFix(benchmark.stats.mean, 2),
164
+ 'sample deviation': numberFix(benchmark.stats.deviation, 2)
165
+ };
166
+ });
167
+
168
+ report[testName].testName = testName;
169
+ const isDone = completedCount === performanceTests.length;
170
+ runTime = Number(runTime.toFixed(2));
171
+ const isTimeWarn = runTime > 120;
172
+ console.log(
173
+ // `Files: ${GREEN}${testFileCount}${END} `,
174
+ // `Suites: ${GREEN}${performanceTests.length}${END} `,
175
+ `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${
176
+ performanceTests.length
177
+ }${END}`,
178
+ `Time: ${isTimeWarn ? YELLOW : GREEN}${runTime}s${END}`
179
+ );
180
+ if (isDone) {
181
+ composeReport();
182
+ }
183
+ })
184
+ .run({async: false});
185
+ }
186
+ });
@@ -0,0 +1 @@
1
+ export * from './reportor';
@@ -0,0 +1,3 @@
1
+ import * as Benchmark from 'benchmark';
2
+
3
+ export type PerformanceTest = {testName: string; suite: Benchmark.Suite; file: string};
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1 @@
1
+ export type AnyFunction = (...args: any[]) => any;
@@ -0,0 +1,2 @@
1
+ export * from './big-o';
2
+ export * from './json2html';
@@ -0,0 +1 @@
1
+ export type Json2htmlOptions = {plainHtml?: boolean} & Partial<{[key: string]: any}>;