data-structure-typed 2.4.5 → 2.5.1
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.
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +3 -1
- package/README.md +78 -31
- package/dist/cjs/binary-tree.cjs +23698 -0
- package/dist/cjs/graph.cjs +5236 -0
- package/dist/cjs/hash.cjs +1262 -0
- package/dist/cjs/heap.cjs +1540 -0
- package/dist/cjs/index.cjs +24509 -2899
- package/dist/cjs/linked-list.cjs +4370 -0
- package/dist/cjs/matrix.cjs +1042 -0
- package/dist/cjs/priority-queue.cjs +1314 -0
- package/dist/cjs/queue.cjs +4090 -0
- package/dist/cjs/stack.cjs +861 -0
- package/dist/cjs/trie.cjs +1173 -0
- package/dist/cjs-legacy/binary-tree.cjs +23730 -0
- package/dist/cjs-legacy/graph.cjs +5234 -0
- package/dist/cjs-legacy/hash.cjs +1262 -0
- package/dist/cjs-legacy/heap.cjs +1537 -0
- package/dist/cjs-legacy/index.cjs +32555 -10936
- package/dist/cjs-legacy/linked-list.cjs +4376 -0
- package/dist/cjs-legacy/matrix.cjs +1045 -0
- package/dist/cjs-legacy/priority-queue.cjs +1312 -0
- package/dist/cjs-legacy/queue.cjs +4088 -0
- package/dist/cjs-legacy/stack.cjs +861 -0
- package/dist/cjs-legacy/trie.cjs +1172 -0
- package/dist/esm/binary-tree.mjs +23683 -0
- package/dist/esm/graph.mjs +5223 -0
- package/dist/esm/hash.mjs +1259 -0
- package/dist/esm/heap.mjs +1534 -0
- package/dist/esm/index.mjs +24507 -2898
- package/dist/esm/linked-list.mjs +4363 -0
- package/dist/esm/matrix.mjs +1038 -0
- package/dist/esm/priority-queue.mjs +1310 -0
- package/dist/esm/queue.mjs +4086 -0
- package/dist/esm/stack.mjs +859 -0
- package/dist/esm/trie.mjs +1170 -0
- package/dist/esm-legacy/binary-tree.mjs +23715 -0
- package/dist/esm-legacy/graph.mjs +5221 -0
- package/dist/esm-legacy/hash.mjs +1259 -0
- package/dist/esm-legacy/heap.mjs +1531 -0
- package/dist/esm-legacy/index.mjs +32553 -10935
- package/dist/esm-legacy/linked-list.mjs +4369 -0
- package/dist/esm-legacy/matrix.mjs +1041 -0
- package/dist/esm-legacy/priority-queue.mjs +1308 -0
- package/dist/esm-legacy/queue.mjs +4084 -0
- package/dist/esm-legacy/stack.mjs +859 -0
- package/dist/esm-legacy/trie.mjs +1169 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +368 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +473 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +931 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +792 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +592 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +320 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3662 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3487 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2778 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3414 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +419 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +384 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +462 -89
- package/dist/types/data-structures/heap/heap.d.ts +567 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +631 -49
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +581 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +775 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +491 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +578 -71
- package/dist/types/data-structures/queue/queue.d.ts +451 -42
- package/dist/types/data-structures/stack/stack.d.ts +374 -32
- package/dist/types/data-structures/trie/trie.d.ts +458 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +32432 -10808
- package/dist/umd/data-structure-typed.min.js +10 -4
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
- package/docs-site-docusaurus/docs/guide/guides.md +611 -0
- package/docs-site-docusaurus/docs/guide/installation.md +60 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
- package/docs-site-docusaurus/docs/guide/overview.md +638 -0
- package/docs-site-docusaurus/docs/guide/performance.md +833 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +71 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/package.json +109 -12
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_label: "PERFORMANCE"
|
|
3
|
+
description: "Benchmarks comparing data-structure-typed vs native Arrays, Maps, and C++ implementations. Includes methodology."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PERFORMANCE
|
|
7
|
+
|
|
8
|
+
Understand how data-structure-typed performs, and when to use each structure.
|
|
9
|
+
|
|
10
|
+
**[Back to README](/.md) • [Architecture Details](/guide/architecture.md) • [Code Examples](/guide/guides.md) • [📈 Interactive HTML Report](/guide/performance)**
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
1. [Performance Summary](#performance-summary)
|
|
17
|
+
2. [Real-World Scenarios](#real-world-scenarios)
|
|
18
|
+
3. [Detailed Benchmarks](#detailed-benchmarks)
|
|
19
|
+
4. [When to Use What](#when-to-use-what)
|
|
20
|
+
5. [Optimization Tips](#optimization-tips)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Performance Summary
|
|
25
|
+
|
|
26
|
+
> **Note on JS vs C++ gaps:** Many “C++ faster” results are primarily explained by **runtime / memory-model differences**, not a flaw in `data-structure-typed`.
|
|
27
|
+
> JavaScript runs on a GC’d VM with boxed numbers, dynamic dispatch, and different cache/memory behavior, while C++ can use tight value types and predictable memory layouts.
|
|
28
|
+
> When the benchmark mixes in baseline containers (Native JS / js-sdsl / C++), treat cross-language comparisons as **directional** and rely most on **within-JS** comparisons for practical decisions.
|
|
29
|
+
|
|
30
|
+
### Key Numbers
|
|
31
|
+
|
|
32
|
+
- **484x faster** than Array.shift() with 100K elements (Deque vs Array)
|
|
33
|
+
- **40x–308x faster** in repeated “update + resort” workloads (RedBlackTree vs Array)
|
|
34
|
+
- **O(log n) guaranteed** on all balanced tree operations
|
|
35
|
+
- **O(1) guaranteed** on Deque head/tail operations
|
|
36
|
+
- Benchmarks include warm-up runs to reduce V8 JIT noise
|
|
37
|
+
|
|
38
|
+
### Performance Tier Chart
|
|
39
|
+
|
|
40
|
+
| Structure | Access | Search | Insert | Delete | Best For |
|
|
41
|
+
|--------------|----------|----------|----------|----------|----------------------|
|
|
42
|
+
| Array | O(1) | O(n) | O(n) | O(n) | Random access |
|
|
43
|
+
| LinkedList | O(n) | O(n) | O(1)* | O(1)* | If you have pointer |
|
|
44
|
+
| Stack | - | - | O(1) | O(1) | LIFO, undo/redo |
|
|
45
|
+
| Queue | - | - | O(1) | O(1) | FIFO, message queues |
|
|
46
|
+
| Deque | - | - | O(1) | O(1) | Head/tail ops |
|
|
47
|
+
| BST | O(log n) | O(log n) | O(log n) | O(log n) | Sorted if balanced |
|
|
48
|
+
| RedBlackTree | O(log n) | O(log n) | O(log n) | O(log n) | Guaranteed sorted |
|
|
49
|
+
| AVL Tree | O(log n) | O(log n) | O(log n) | O(log n) | Max search speed |
|
|
50
|
+
| Heap | O(n) | O(n) | O(log n) | O(log n) | Priority queue |
|
|
51
|
+
| Trie | N/A | O(m) | O(m) | O(m) | Prefix search |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Benchmark
|
|
56
|
+
|
|
57
|
+
[//]: # (No deletion!!! Start of Replace Section)
|
|
58
|
+
|
|
59
|
+
### Queue
|
|
60
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
61
|
+
|-----------|----------|----------|----------|-----------|
|
|
62
|
+
| 1M push | 26.93 | 24.41 | 51.97 | ±4.28% |
|
|
63
|
+
| 100K push & shift | 3.45 | 2.72 | 15.26 | ±8.97% |
|
|
64
|
+
|
|
65
|
+
#### Queue (side-by-side)
|
|
66
|
+
|
|
67
|
+
> Comparison table. The main table above is Queue only.
|
|
68
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
69
|
+
|
|
70
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
71
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
72
|
+
| 1M push | 26.93 | 23.83 | 1.70 | 27.59 |
|
|
73
|
+
| 100K push & shift | 3.45 | 1152.77 | 0.20 | 2.71 |
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Deque
|
|
77
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
78
|
+
|-----------|----------|----------|----------|-----------|
|
|
79
|
+
| 1M push | 9.77 | 6.27 | 21.63 | ±9.28% |
|
|
80
|
+
| 1M push & pop | 14.75 | 11.80 | 31.16 | ±5.06% |
|
|
81
|
+
| 1M push & shift | 14.61 | 13.31 | 40.42 | ±5.25% |
|
|
82
|
+
| 100K push & shift | 1.29 | 1.19 | 3.37 | ±3.91% |
|
|
83
|
+
| 100K unshift & shift | 1.26 | 1.14 | 2.75 | ±3.59% |
|
|
84
|
+
|
|
85
|
+
#### Deque (side-by-side)
|
|
86
|
+
|
|
87
|
+
> Comparison table. The main table above is Deque only.
|
|
88
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
89
|
+
|
|
90
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
91
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
92
|
+
| 1M push | 9.77 | 26.81 | 1.76 | 7.79 |
|
|
93
|
+
| 1M push & pop | 14.75 | 27.96 | 2.20 | 12.34 |
|
|
94
|
+
| 1M push & shift | 14.61 | - | 1.94 | - |
|
|
95
|
+
| 100K push & shift | 1.29 | 1243.77 | 0.19 | 1.17 |
|
|
96
|
+
| 100K unshift & shift | 1.26 | 1867.28 | 0.19 | 1.17 |
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### DoublyLinkedList
|
|
100
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
101
|
+
|-----------|----------|----------|----------|-----------|
|
|
102
|
+
| 100k push | 5.70 | 4.80 | 7.27 | ±1.57% |
|
|
103
|
+
| 100k unshift | 5.57 | 4.63 | 13.65 | ±5.7% |
|
|
104
|
+
| 100k unshift & shift | 4.04 | 3.87 | 5.34 | ±1.3% |
|
|
105
|
+
| 100k addAt(mid) | 1865.99 | 1778.94 | 1992.65 | ±5.43% |
|
|
106
|
+
| 100k addBefore (cursor) | 6.81 | 5.32 | 17.77 | ±4.44% |
|
|
107
|
+
|
|
108
|
+
#### DoublyLinkedList (side-by-side)
|
|
109
|
+
|
|
110
|
+
> Comparison table. The main table above is DoublyLinkedList only.
|
|
111
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
112
|
+
|
|
113
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
114
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
115
|
+
| 100k push | 5.70 | 2.40 | 5.70 | 1.90 |
|
|
116
|
+
| 100k unshift | 5.57 | 884.06 | 5.85 | 1.52 |
|
|
117
|
+
| 100k unshift & shift | 4.04 | 2050.71 | 5.74 | 1.89 |
|
|
118
|
+
| 100k addAt(mid) | 1865.99 | - | 754.81 | - |
|
|
119
|
+
| 100k addBefore (cursor) | 6.81 | - | 6.18 | - |
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
### SinglyLinkedList
|
|
123
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
124
|
+
|-----------|----------|----------|----------|-----------|
|
|
125
|
+
| 100K unshift & shift | 3.77 | 3.62 | 3.99 | ±0.41% |
|
|
126
|
+
| 10K unshift & shift | 0.37 | 0.36 | 0.44 | ±0.78% |
|
|
127
|
+
| 10K addAt(mid) | 18.61 | 17.61 | 25.55 | ±1.66% |
|
|
128
|
+
| 10K addBefore (cursor) | 17.56 | 16.67 | 20.17 | ±1.11% |
|
|
129
|
+
|
|
130
|
+
#### SinglyLinkedList (side-by-side)
|
|
131
|
+
|
|
132
|
+
> Comparison table. The main table above is SinglyLinkedList only.
|
|
133
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
134
|
+
|
|
135
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
136
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
137
|
+
| 100K unshift & shift | 3.77 | 1958.39 | 4.80 | - |
|
|
138
|
+
| 10K unshift & shift | 0.37 | 6.26 | 0.47 | - |
|
|
139
|
+
| 10K addAt(mid) | 18.61 | - | 5.77 | - |
|
|
140
|
+
| 10K addBefore (cursor) | 17.56 | - | 0.53 | - |
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### PriorityQueue
|
|
144
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
145
|
+
|-----------|----------|----------|----------|-----------|
|
|
146
|
+
| 100K add | 4.00 | 3.80 | 4.41 | ±0.6% |
|
|
147
|
+
| 100K add & poll | 22.51 | 21.23 | 42.99 | ±3.19% |
|
|
148
|
+
|
|
149
|
+
#### PriorityQueue (side-by-side)
|
|
150
|
+
|
|
151
|
+
> Comparison table. The main table above is PriorityQueue only.
|
|
152
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
153
|
+
|
|
154
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
155
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
156
|
+
| 100K add | 4.00 | - | 1.05 | 4.96 |
|
|
157
|
+
| 100K add & poll | 22.51 | - | 4.53 | 22.97 |
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
### TreeSet
|
|
161
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
162
|
+
|-----------|----------|----------|----------|-----------|
|
|
163
|
+
| 1M add | 995.72 | 948.08 | 1124.92 | ±6.28% |
|
|
164
|
+
| 1M has | 67.80 | 64.53 | 86.26 | ±1.67% |
|
|
165
|
+
| 100K rangeSearch | 17.34 | 16.79 | 18.81 | ±0.46% |
|
|
166
|
+
| 100K navigable | 118.65 | 117.95 | 119.38 | ±0.14% |
|
|
167
|
+
|
|
168
|
+
#### TreeSet (side-by-side)
|
|
169
|
+
|
|
170
|
+
> Comparison table. The main table above is TreeSet only.
|
|
171
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
172
|
+
|
|
173
|
+
| Test Case | DST (ms) | DST classic (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
174
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: | ---------: |
|
|
175
|
+
| 1M add | 995.72 | 807.88 | - | 462.00 | 677.58 |
|
|
176
|
+
| 1M has | 67.80 | 747.62 | - | 444.00 | 655.62 |
|
|
177
|
+
| 100K rangeSearch | 17.34 | 16.70 | - | - | - |
|
|
178
|
+
| 100K navigable | 118.65 | 123.91 | - | - | - |
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### TreeMap
|
|
182
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
183
|
+
|-----------|----------|----------|----------|-----------|
|
|
184
|
+
| 1M set | 978.72 | 934.59 | 1130.02 | ±6.39% |
|
|
185
|
+
| 1M get | 127.82 | 123.10 | 133.96 | ±1.2% |
|
|
186
|
+
| 100K rangeSearch | 38.17 | 34.80 | 100.14 | ±6.97% |
|
|
187
|
+
| 100K navigable | 160.66 | 151.89 | 307.88 | ±9.6% |
|
|
188
|
+
|
|
189
|
+
#### TreeMap (side-by-side)
|
|
190
|
+
|
|
191
|
+
> Comparison table. The main table above is TreeMap only.
|
|
192
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
193
|
+
|
|
194
|
+
| Test Case | DST (ms) | DST classic (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
195
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: | ---------: |
|
|
196
|
+
| 1M set | 978.72 | 831.32 | - | 512.00 | 623.23 |
|
|
197
|
+
| 1M get | 127.82 | 719.05 | - | 322.00 | 626.87 |
|
|
198
|
+
| 100K rangeSearch | 38.17 | 34.42 | - | - | - |
|
|
199
|
+
| 100K navigable | 160.66 | 213.76 | - | - | - |
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
### TreeMultiSet
|
|
203
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
204
|
+
|-----------|----------|----------|----------|-----------|
|
|
205
|
+
| 1M add (TreeMultiSet expanded iteration) | 217.73 | 191.17 | 319.78 | ±8.07% |
|
|
206
|
+
| 1M has-only (TreeMultiSet) | 67.67 | 66.08 | 72.83 | ±0.72% |
|
|
207
|
+
| 1M count-only (TreeMultiSet) | 55.74 | 53.94 | 57.60 | ±0.49% |
|
|
208
|
+
| 1M build+has (TreeMultiSet) | 260.84 | 248.30 | 300.22 | ±2.79% |
|
|
209
|
+
| 1M build+count (TreeMultiSet) | 267.81 | 242.77 | 339.53 | ±5.97% |
|
|
210
|
+
| 100K delete-one (TreeMultiSet) | 217.76 | 201.92 | 254.80 | ±2.97% |
|
|
211
|
+
| 100K setCount (TreeMultiSet) | 214.66 | 201.65 | 264.54 | ±3.65% |
|
|
212
|
+
| 1M expanded iteration (TreeMultiSet) | 54.41 | 53.14 | 62.22 | ±0.78% |
|
|
213
|
+
| 1M entries view (TreeMultiSet) | 15.67 | 14.81 | 17.19 | ±0.72% |
|
|
214
|
+
| 1M size property (TreeMultiSet) | 0.00 | 0.00 | 0.00 | ±3.47% |
|
|
215
|
+
| 1M distinctSize property (TreeMultiSet) | 0.00 | 0.00 | 0.00 | ±3.88% |
|
|
216
|
+
|
|
217
|
+
#### TreeMultiSet (side-by-side)
|
|
218
|
+
|
|
219
|
+
> Comparison table. The main table above is TreeMultiSet only.
|
|
220
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
221
|
+
|
|
222
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
223
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
224
|
+
| 1M add (TreeMultiSet expanded iteration) | 217.73 | - | 752.00 | - |
|
|
225
|
+
| 1M has-only (TreeMultiSet) | 67.67 | - | 756.00 | - |
|
|
226
|
+
| 1M count-only (TreeMultiSet) | 55.74 | - | 1332.00 | - |
|
|
227
|
+
| 1M build+has (TreeMultiSet) | 260.84 | - | 1406.00 | - |
|
|
228
|
+
| 1M build+count (TreeMultiSet) | 267.81 | - | 1909.00 | - |
|
|
229
|
+
| 100K delete-one (TreeMultiSet) | 217.76 | - | - | - |
|
|
230
|
+
| 100K setCount (TreeMultiSet) | 214.66 | - | - | - |
|
|
231
|
+
| 1M expanded iteration (TreeMultiSet) | 54.41 | - | - | - |
|
|
232
|
+
| 1M entries view (TreeMultiSet) | 15.67 | - | - | - |
|
|
233
|
+
| 1M size property (TreeMultiSet) | 0.00 | - | - | - |
|
|
234
|
+
| 1M distinctSize property (TreeMultiSet) | 0.00 | - | - | - |
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
### TreeMultiMap
|
|
238
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
239
|
+
|-----------|----------|----------|----------|-----------|
|
|
240
|
+
| 1M add (TreeMultiMap bucketed) | 366.19 | 346.31 | 454.65 | ±5.51% |
|
|
241
|
+
| 1M has-only (TreeMultiMap) | 35.37 | 34.94 | 36.94 | ±0.39% |
|
|
242
|
+
| 1M get-only (TreeMultiMap) | 58.37 | 56.05 | 73.86 | ±1.37% |
|
|
243
|
+
| 1M count-only (TreeMultiMap) | 105.34 | 94.16 | 124.54 | ±2.71% |
|
|
244
|
+
| 1M build+has (TreeMultiMap) | 396.87 | 373.62 | 538.68 | ±8.08% |
|
|
245
|
+
| 1M build+get (TreeMultiMap) | 416.59 | 412.46 | 424.84 | ±0.62% |
|
|
246
|
+
| 100K hasEntry (TreeMultiMap Object.is) | 375.85 | 346.85 | 396.95 | ±2.39% |
|
|
247
|
+
| 100K deleteValue (TreeMultiMap Object.is) | 411.69 | 388.10 | 577.77 | ±9.06% |
|
|
248
|
+
| 100K firstEntry/lastEntry (TreeMultiMap) | 0.00 | - | - | ±0% |
|
|
249
|
+
| 100K ceilingEntry/floorEntry (TreeMultiMap) | 0.00 | - | - | ±0% |
|
|
250
|
+
| 1M bucket iteration (TreeMultiMap) | 22.55 | 21.91 | 25.20 | ±0.68% |
|
|
251
|
+
| 1M flatEntries iteration (TreeMultiMap) | 106.47 | 104.33 | 110.52 | ±0.6% |
|
|
252
|
+
| 1M size property (TreeMultiMap) | 0.00 | 0.00 | 0.00 | ±4.08% |
|
|
253
|
+
| 1M totalSize property (TreeMultiMap) | 21.74 | 21.09 | 25.40 | ±0.8% |
|
|
254
|
+
|
|
255
|
+
#### TreeMultiMap (side-by-side)
|
|
256
|
+
|
|
257
|
+
> Comparison table. The main table above is TreeMultiMap only.
|
|
258
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
259
|
+
|
|
260
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
261
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
262
|
+
| 1M add (TreeMultiMap bucketed) | 366.19 | - | 731.00 | - |
|
|
263
|
+
| 1M has-only (TreeMultiMap) | 35.37 | - | 833.00 | - |
|
|
264
|
+
| 1M get-only (TreeMultiMap) | 58.37 | - | 1553.00 | - |
|
|
265
|
+
| 1M count-only (TreeMultiMap) | 105.34 | - | 1548.00 | - |
|
|
266
|
+
| 1M build+has (TreeMultiMap) | 396.87 | - | 1519.00 | - |
|
|
267
|
+
| 1M build+get (TreeMultiMap) | 416.59 | - | 2263.00 | - |
|
|
268
|
+
| 100K hasEntry (TreeMultiMap Object.is) | 375.85 | - | - | - |
|
|
269
|
+
| 100K deleteValue (TreeMultiMap Object.is) | 411.69 | - | - | - |
|
|
270
|
+
| 100K firstEntry/lastEntry (TreeMultiMap) | 0.00 | - | - | - |
|
|
271
|
+
| 100K ceilingEntry/floorEntry (TreeMultiMap) | 0.00 | - | - | - |
|
|
272
|
+
| 1M bucket iteration (TreeMultiMap) | 22.55 | - | 109.00 | - |
|
|
273
|
+
| 1M flatEntries iteration (TreeMultiMap) | 106.47 | - | 109.00 | - |
|
|
274
|
+
| 1M size property (TreeMultiMap) | 0.00 | - | - | - |
|
|
275
|
+
| 1M totalSize property (TreeMultiMap) | 21.74 | - | - | - |
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
### RedBlackTree
|
|
279
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
280
|
+
|-----------|----------|----------|----------|-----------|
|
|
281
|
+
| 1M get | 99.24 | 82.27 | 109.67 | ±16.59% |
|
|
282
|
+
| 200K rangeSearch SEQ | 1365.15 | 1251.75 | 1491.01 | ±9.18% |
|
|
283
|
+
| 200K rangeSearch RAND | 1565.26 | 1528.89 | 1613.47 | ±2.69% |
|
|
284
|
+
| 1M upd SEQ | 84.75 | 82.26 | 86.85 | ±3.10% |
|
|
285
|
+
| 1M upd RAND | 113.72 | 112.51 | 116.12 | ±1.70% |
|
|
286
|
+
| 1M ins SEQ | 535.64 | 459.83 | 795.68 | ±33.88% |
|
|
287
|
+
| 1M ins RAND | 989.88 | 973.81 | 1001.58 | ±1.43% |
|
|
288
|
+
| 1M keys-only | 4.22 | 2.71 | 5.81 | ±41.71% |
|
|
289
|
+
|
|
290
|
+
#### RedBlackTree (side-by-side)
|
|
291
|
+
|
|
292
|
+
> Comparison table. The main table above is RedBlackTree only.
|
|
293
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
294
|
+
|
|
295
|
+
| Test Case | DST (ms) | DST classic (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
296
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: | ---------: |
|
|
297
|
+
| 1M get | 99.24 | 304.72 | - | 52.97 | - |
|
|
298
|
+
| 200K rangeSearch SEQ | 1365.15 | - | - | - | - |
|
|
299
|
+
| 200K rangeSearch RAND | 1565.26 | - | - | - | - |
|
|
300
|
+
| 1M upd SEQ | 84.75 | 302.03 | - | 68.43 | - |
|
|
301
|
+
| 1M upd RAND | 113.72 | 422.53 | - | 158.14 | - |
|
|
302
|
+
| 1M ins SEQ | 535.64 | 211.38 | - | 162.72 | - |
|
|
303
|
+
| 1M ins RAND | 989.88 | 882.76 | - | 483.56 | - |
|
|
304
|
+
| 1M keys-only | 4.22 | - | - | 0.09 | - |
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
### BST
|
|
308
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
309
|
+
|-----------|----------|----------|----------|-----------|
|
|
310
|
+
| 10K add randomly | 5.50 | 5.11 | 5.93 | ±0.6% |
|
|
311
|
+
| 10K add & delete randomly | 10.01 | 9.75 | 10.79 | ±0.4% |
|
|
312
|
+
| 10K addMany | 11.62 | 10.00 | 68.37 | ±15.54% |
|
|
313
|
+
| 10K get | 10.65 | 10.35 | 11.67 | ±0.48% |
|
|
314
|
+
|
|
315
|
+
#### BST (side-by-side)
|
|
316
|
+
|
|
317
|
+
> Comparison table. The main table above is BST only.
|
|
318
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
319
|
+
|
|
320
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
321
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
322
|
+
| 10K add randomly | 5.50 | - | - | - |
|
|
323
|
+
| 10K add & delete randomly | 10.01 | - | - | - |
|
|
324
|
+
| 10K addMany | 11.62 | - | - | - |
|
|
325
|
+
| 10K get | 10.65 | - | - | - |
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
### BinaryTree
|
|
329
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
330
|
+
|-----------|----------|----------|----------|-----------|
|
|
331
|
+
| 1K add randomly | 9.77 | 9.52 | 10.28 | ±0.36% |
|
|
332
|
+
| 1K add & delete randomly | 10.05 | 9.67 | 11.34 | ±0.69% |
|
|
333
|
+
| 1K addMany | 10.79 | 9.20 | 84.26 | ±19.64% |
|
|
334
|
+
| 1K get | 9.64 | 9.15 | 12.52 | ±1.33% |
|
|
335
|
+
| 1K has | 9.50 | 9.20 | 11.91 | ±0.76% |
|
|
336
|
+
| 1K dfs | 92.87 | 90.46 | 96.24 | ±0.62% |
|
|
337
|
+
| 1K bfs | 37.34 | 36.18 | 42.30 | ±0.7% |
|
|
338
|
+
| 1K morris | 37.49 | 36.29 | 39.54 | ±0.51% |
|
|
339
|
+
|
|
340
|
+
#### BinaryTree (side-by-side)
|
|
341
|
+
|
|
342
|
+
> Comparison table. The main table above is BinaryTree only.
|
|
343
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
344
|
+
|
|
345
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
346
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
347
|
+
| 1K add randomly | 9.77 | - | - | - |
|
|
348
|
+
| 1K add & delete randomly | 10.05 | - | - | - |
|
|
349
|
+
| 1K addMany | 10.79 | - | - | - |
|
|
350
|
+
| 1K get | 9.64 | - | - | - |
|
|
351
|
+
| 1K has | 9.50 | - | - | - |
|
|
352
|
+
| 1K dfs | 92.87 | - | - | - |
|
|
353
|
+
| 1K bfs | 37.34 | - | - | - |
|
|
354
|
+
| 1K morris | 37.49 | - | - | - |
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
### HashMap
|
|
358
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
359
|
+
|-----------|----------|----------|----------|-----------|
|
|
360
|
+
| 1M set | 146.17 | 84.97 | 644.99 | ±33.94% |
|
|
361
|
+
| 1M set & get | 141.88 | 106.42 | 178.02 | ±6.1% |
|
|
362
|
+
| 1M ObjKey set & get | 223.16 | 210.45 | 300.73 | ±5.48% |
|
|
363
|
+
|
|
364
|
+
#### HashMap (side-by-side)
|
|
365
|
+
|
|
366
|
+
> Comparison table. The main table above is HashMap only.
|
|
367
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
368
|
+
|
|
369
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
370
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
371
|
+
| 1M set | 146.17 | 144.83 | 76.26 | 94.16 |
|
|
372
|
+
| 1M set & get | 141.88 | 200.47 | 75.25 | 67.16 |
|
|
373
|
+
| 1M ObjKey set & get | 223.16 | 206.62 | 84.40 | 382.79 |
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
### Trie
|
|
377
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
378
|
+
|-----------|----------|----------|----------|-----------|
|
|
379
|
+
| 100K add | 141.10 | 78.57 | 1348.32 | ±65.27% |
|
|
380
|
+
| 100K getWords | 57.16 | 52.58 | 63.12 | ±1.37% |
|
|
381
|
+
|
|
382
|
+
#### Trie (side-by-side)
|
|
383
|
+
|
|
384
|
+
> Comparison table. The main table above is Trie only.
|
|
385
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
386
|
+
|
|
387
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
388
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
389
|
+
| 100K add | 141.10 | - | - | - |
|
|
390
|
+
| 100K getWords | 57.16 | - | - | - |
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
### DirectedGraph
|
|
394
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
395
|
+
|-----------|----------|----------|----------|-----------|
|
|
396
|
+
| 1K addVertex | 0.05 | 0.05 | 0.05 | ±0.43% |
|
|
397
|
+
| 1K addEdge | 0.00 | - | - | ±0% |
|
|
398
|
+
| 1K getVertex | 37.54 | 36.05 | 38.86 | ±0.39% |
|
|
399
|
+
| 1K getEdge | 74.48 | 72.60 | 77.63 | ±0.44% |
|
|
400
|
+
| tarjan | 0.38 | 0.34 | 0.42 | ±0.93% |
|
|
401
|
+
| topologicalSort | 0.24 | 0.23 | 0.26 | ±0.51% |
|
|
402
|
+
|
|
403
|
+
#### DirectedGraph (side-by-side)
|
|
404
|
+
|
|
405
|
+
> Comparison table. The main table above is DirectedGraph only.
|
|
406
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
407
|
+
|
|
408
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
409
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
410
|
+
| 1K addVertex | 0.05 | - | - | - |
|
|
411
|
+
| 1K addEdge | 0.00 | - | - | - |
|
|
412
|
+
| 1K getVertex | 37.54 | - | - | - |
|
|
413
|
+
| 1K getEdge | 74.48 | - | - | - |
|
|
414
|
+
| tarjan | 0.38 | - | - | - |
|
|
415
|
+
| topologicalSort | 0.24 | - | - | - |
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
### Stack
|
|
419
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
420
|
+
|-----------|----------|----------|----------|-----------|
|
|
421
|
+
| 1M push | 46.38 | 31.28 | 258.38 | ±26.06% |
|
|
422
|
+
| 1M push & pop | 34.59 | 27.52 | 121.56 | ±14.83% |
|
|
423
|
+
|
|
424
|
+
#### Stack (side-by-side)
|
|
425
|
+
|
|
426
|
+
> Comparison table. The main table above is Stack only.
|
|
427
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
428
|
+
|
|
429
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
430
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
431
|
+
| 1M push | 46.38 | 30.28 | 1.65 | 32.38 |
|
|
432
|
+
| 1M push & pop | 34.59 | 34.53 | 2.62 | 34.45 |
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
### red-black-tree-cjs
|
|
436
|
+
| Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
|
|
437
|
+
|-----------|----------|----------|----------|-----------|
|
|
438
|
+
| 1M get | 97.57 | 75.66 | 115.14 | ±22.94% |
|
|
439
|
+
| 1M upd SEQ | 85.76 | 78.96 | 92.92 | ±8.16% |
|
|
440
|
+
| 1M upd RAND | 113.48 | 101.84 | 120.90 | ±7.77% |
|
|
441
|
+
| 1M ins SEQ | 493.45 | 436.86 | 670.44 | ±25.42% |
|
|
442
|
+
| 1M ins RAND | 1023.19 | 976.56 | 1094.17 | ±5.36% |
|
|
443
|
+
| 1M keys-only | 4.22 | 2.71 | 5.90 | ±41.83% |
|
|
444
|
+
|
|
445
|
+
#### red-black-tree-cjs (side-by-side)
|
|
446
|
+
|
|
447
|
+
> Comparison table. The main table above is red-black-tree-cjs only.
|
|
448
|
+
> Native is `-` when there is no apples-to-apples equivalent in this benchmark.
|
|
449
|
+
|
|
450
|
+
| Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
|
|
451
|
+
| ----------- | ---------: | ---------: | ---------: | ---------: |
|
|
452
|
+
| 1M get | 97.57 | - | - | - |
|
|
453
|
+
| 1M upd SEQ | 85.76 | - | - | - |
|
|
454
|
+
| 1M upd RAND | 113.48 | - | - | - |
|
|
455
|
+
| 1M ins SEQ | 493.45 | - | - | - |
|
|
456
|
+
| 1M ins RAND | 1023.19 | - | - | - |
|
|
457
|
+
| 1M keys-only | 4.22 | - | - | - |
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
[//]: # (No deletion!!! End of Replace Section)
|
|
462
|
+
|
|
463
|
+
## Real-World Scenarios
|
|
464
|
+
|
|
465
|
+
### Scenario 1: Message Queue Processing
|
|
466
|
+
|
|
467
|
+
**Problem**: Process 100,000 messages in a queue.
|
|
468
|
+
|
|
469
|
+
```javascript
|
|
470
|
+
// ❌ Array.shift() approach
|
|
471
|
+
const queue = [];
|
|
472
|
+
for (let msg of incomingMessages) queue.push(msg);
|
|
473
|
+
for (let i = 0; i < 100000; i++) {
|
|
474
|
+
const msg = queue.shift(); // O(n) each time!
|
|
475
|
+
processMessage(msg);
|
|
476
|
+
}
|
|
477
|
+
// Total: 100,000 * O(n) = O(n²)
|
|
478
|
+
// Time: ~2829ms for 100K items
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
```javascript
|
|
482
|
+
// ✅ Deque approach
|
|
483
|
+
import { Deque } from 'data-structure-typed';
|
|
484
|
+
|
|
485
|
+
const deque = new Deque();
|
|
486
|
+
for (let msg of incomingMessages) deque.push(msg);
|
|
487
|
+
for (let i = 0; i < 100000; i++) {
|
|
488
|
+
const msg = deque.shift(); // O(1)!
|
|
489
|
+
processMessage(msg);
|
|
490
|
+
}
|
|
491
|
+
// Total: 100,000 * O(1) = O(n)
|
|
492
|
+
// Time: ~5.83ms for 100K items
|
|
493
|
+
|
|
494
|
+
// 484x faster!
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
**Real Impact**: In a system handling 10,000 requests/second, this saves 475ms per second of latency.
|
|
498
|
+
|
|
499
|
+
### Scenario 2: Leaderboard Ranking
|
|
500
|
+
|
|
501
|
+
**Problem**: Maintain top 100 players with constantly changing scores.
|
|
502
|
+
|
|
503
|
+
```javascript
|
|
504
|
+
// ❌ Array approach
|
|
505
|
+
const players = [];
|
|
506
|
+
|
|
507
|
+
function updateScore(playerId, newScore) {
|
|
508
|
+
const idx = players.findIndex(p => p.id === playerId);
|
|
509
|
+
players[idx].score = newScore;
|
|
510
|
+
players.sort((a, b) => b.score - a.score); // O(n log n) each time!
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// After 1000 updates: 1000 * O(n log n) = O(n² log n)
|
|
514
|
+
// Time: ~2500ms for maintaining ranking of 100 players
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
```javascript
|
|
518
|
+
// ✅ RedBlackTree approach
|
|
519
|
+
import { RedBlackTree } from 'data-structure-typed';
|
|
520
|
+
|
|
521
|
+
const leaderboard = new RedBlackTree<number, number>();
|
|
522
|
+
|
|
523
|
+
function updateScore(playerId, newScore) {
|
|
524
|
+
// Keyed by playerId: updates are a single O(log n) set.
|
|
525
|
+
// (If you need to *rank by score*, use score as (part of) the key and maintain a playerId→score index.)
|
|
526
|
+
leaderboard.set(playerId, newScore);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// After 1000 updates: 1000 * O(log n) = O(n log n)
|
|
530
|
+
// Time: ~8ms for 1000 updates on 100 players (measured in PERFORMANCE.md)
|
|
531
|
+
|
|
532
|
+
// ~312x faster than sorting on every update
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**Real Impact**: Live leaderboards update instantly instead of lagging.
|
|
536
|
+
|
|
537
|
+
### Scenario 3: Task Scheduling by Priority
|
|
538
|
+
|
|
539
|
+
**Problem**: Execute tasks in priority order with 10K pending tasks.
|
|
540
|
+
|
|
541
|
+
```javascript
|
|
542
|
+
// ❌ Manual priority handling
|
|
543
|
+
const tasks = [];
|
|
544
|
+
|
|
545
|
+
function addTask(task) {
|
|
546
|
+
tasks.push(task);
|
|
547
|
+
tasks.sort((a, b) => b.priority - a.priority); // O(n log n)
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function nextTask() {
|
|
551
|
+
return tasks.shift(); // O(n)
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Adding 10K tasks: 10K * O(n log n) = O(n² log n)
|
|
555
|
+
// Time: ~3200ms
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
```javascript
|
|
559
|
+
// ✅ PriorityQueue approach
|
|
560
|
+
import { MaxPriorityQueue } from 'data-structure-typed';
|
|
561
|
+
|
|
562
|
+
const pq = new MaxPriorityQueue();
|
|
563
|
+
|
|
564
|
+
function addTask(task) {
|
|
565
|
+
pq.add(task); // O(log n)
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function nextTask() {
|
|
569
|
+
return pq.poll(); // O(log n)
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// Adding 10K tasks: 10K * O(log n) = O(n log n)
|
|
573
|
+
// Time: ~45ms
|
|
574
|
+
|
|
575
|
+
// 71x faster!
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## Detailed Benchmarks
|
|
581
|
+
|
|
582
|
+
### Deque vs Array Performance
|
|
583
|
+
|
|
584
|
+
| Operation | Array | Deque | Speed-up |
|
|
585
|
+
|-----------------|--------|--------|----------|
|
|
586
|
+
| 100K shifts | 2829ms | 5.83ms | **485x** |
|
|
587
|
+
| 100K unshifts | 2847ms | 6.12ms | **465x** |
|
|
588
|
+
| 100K operations | 2900ms | 7.45ms | **390x** |
|
|
589
|
+
|
|
590
|
+
### Sorting Performance
|
|
591
|
+
|
|
592
|
+
| Data Size | Array.sort | RedBlackTree | Speed-up |
|
|
593
|
+
|------------|------------|--------------|---------------------|
|
|
594
|
+
| 1K items | 0.8ms | 3.2ms* | 0.25x (sort faster) |
|
|
595
|
+
| 10K items | 12ms | 18ms** | ~0.66x |
|
|
596
|
+
| 100K items | 150ms | 165ms** | ~0.9x |
|
|
597
|
+
| 1M items | 1800ms | 1950ms** | ~0.92x |
|
|
598
|
+
|
|
599
|
+
*First time - not repeated sorts
|
|
600
|
+
**Maintains sorted order throughout
|
|
601
|
+
|
|
602
|
+
**Key Insight**: For repeated operations (updates with resorts), RBTree is much faster:
|
|
603
|
+
|
|
604
|
+
| Scenario | Array | RBTree | Speed-up |
|
|
605
|
+
|---------------------------|---------|--------|----------|
|
|
606
|
+
| Insert 1K, sort once | 2ms | 5ms | 0.4x |
|
|
607
|
+
| Insert 1K, resort 100x | 200ms | 5ms | **40x** |
|
|
608
|
+
| Insert 100K, resort 1000x | 20000ms | 65ms | **308x** |
|
|
609
|
+
|
|
610
|
+
### Search Performance
|
|
611
|
+
|
|
612
|
+
| Structure | 1K items | 10K items | 100K items |
|
|
613
|
+
|----------------|----------|-----------|------------|
|
|
614
|
+
| Array (linear) | 0.5ms | 5ms | 50ms |
|
|
615
|
+
| BST (balanced) | 0.01ms | 0.013ms | 0.015ms |
|
|
616
|
+
| RedBlackTree | 0.01ms | 0.013ms | 0.015ms |
|
|
617
|
+
| HashMap | 0.001ms | 0.001ms | 0.001ms |
|
|
618
|
+
|
|
619
|
+
### Memory Usage
|
|
620
|
+
|
|
621
|
+
| Data Structure | 1K items | 10K items | 100K items | 1M items |
|
|
622
|
+
|------------------|----------|-----------|------------|------------|
|
|
623
|
+
| Array | 39 KB | 242 KB | 2,706 KB | 21,519 KB |
|
|
624
|
+
| Queue | 38 KB | 248 KB | 2,712 KB | 21,527 KB |
|
|
625
|
+
| Deque | 53 KB | 147 KB | 1,341 KB | 10,717 KB |
|
|
626
|
+
| SinglyLinkedList | 60 KB | 425 KB | 3,947 KB | 39,100 KB |
|
|
627
|
+
| DoublyLinkedList | 60 KB | 502 KB | 4,726 KB | 46,909 KB |
|
|
628
|
+
| Stack | 42 KB | 240 KB | 2,709 KB | 21,521 KB |
|
|
629
|
+
| Heap | 35 KB | 250 KB | 2,716 KB | 21,530 KB |
|
|
630
|
+
| PriorityQueue | 39 KB | 245 KB | 2,711 KB | 21,524 KB |
|
|
631
|
+
| Trie | 526 KB | 3,040 KB | 29,160 KB | 270,733 KB |
|
|
632
|
+
| RedBlackTree | 570 KB | 1,069 KB | 8,765 KB | 86,035 KB |
|
|
633
|
+
| TreeCounter | 553 KB | 1,134 KB | 11,099 KB | 91,415 KB |
|
|
634
|
+
| TreeMultiMap | 2,069 KB | 4,836 KB | 32,828 KB | 208,619 KB |
|
|
635
|
+
|
|
636
|
+
### C++ vs JavaScript Data Structure Memory Usage Comparison (1M Elements)
|
|
637
|
+
|
|
638
|
+
| Data Structure | C++ | JavaScript | Multiple | Evaluation |
|
|
639
|
+
|------------------|-----------|------------|-------------|------------------------------------------------------------------------------------------|
|
|
640
|
+
| Array | 4–8 MB | 21.01 MB | 2.75×–5.51× | JavaScript uses significantly more memory due to object model and GC overhead |
|
|
641
|
+
| Queue | 8–24 MB | 21.02 MB | 0.92×–2.76× | Memory usage depends heavily on the C++ implementation strategy |
|
|
642
|
+
| Deque | 8–24 MB | 10.47 MB | 0.46×–1.37× | JavaScript implementation is relatively memory-efficient in this case |
|
|
643
|
+
| SinglyLinkedList | 24–40 MB | 38.18 MB | 1.00×–1.67× | Similar memory footprint; both suffer from per-node allocation overhead |
|
|
644
|
+
| DoublyLinkedList | 32–56 MB | 45.81 MB | 0.86×–1.50× | Comparable memory usage; allocator overhead dominates in both languages |
|
|
645
|
+
| Stack | 4–8 MB | 21.02 MB | 2.75×–5.51× | JavaScript stacks are much heavier than C++ vector-based stacks |
|
|
646
|
+
| Heap | 4–8 MB | 21.03 MB | 2.76×–5.51× | JavaScript heap implementations incur substantial runtime overhead |
|
|
647
|
+
| PriorityQueue | 4–8 MB | 21.02 MB | 2.76×–5.51× | Similar to Heap; JavaScript pays extra metadata and GC costs |
|
|
648
|
+
| Trie | 32–160 MB | 264.39 MB | 1.73×–8.66× | Highly implementation-dependent; JavaScript object-based tries are very memory-intensive |
|
|
649
|
+
| RedBlackTree | 48–80 MB | 84.02 MB | 1.10×–1.84× | JavaScript trees are larger, but the gap is moderate compared to arrays |
|
|
650
|
+
| TreeCounter | 56–88 MB | 89.27 MB | 1.06×–1.67× | Additional per-node bookkeeping increases JavaScript memory usage |
|
|
651
|
+
| TreeMultiMap | 56–96 MB | 203.73 MB | 2.23×–3.81× | Deep object nesting significantly amplifies memory consumption in JavaScript |
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
|
|
655
|
+
## When to Use What
|
|
656
|
+
|
|
657
|
+
### Decision Matrix
|
|
658
|
+
|
|
659
|
+
| Need... | Use... | Complexity | Notes |
|
|
660
|
+
|---------------------------|---------------|---------------------|--------------------|
|
|
661
|
+
| Random access by index | Array | O(1) access | Standard choice |
|
|
662
|
+
| Sorted order with updates | RedBlackTree | O(log n) all ops | Auto-maintained |
|
|
663
|
+
| Priority queue | PriorityQueue | O(log n) add/remove | Keeps order |
|
|
664
|
+
| Fast head/tail ops | Deque | O(1) all ops | Best for queues |
|
|
665
|
+
| Prefix search | Trie | O(m+k) | m=prefix length |
|
|
666
|
+
| Undo/redo stack | Stack | O(1) all ops | LIFO order |
|
|
667
|
+
| Message queue | Queue/Deque | O(1) all ops | FIFO order |
|
|
668
|
+
| Graph algorithms | DirectedGraph | Varies | DFS, BFS, Dijkstra |
|
|
669
|
+
| Key-value lookup | Map | O(1) avg | When unsorted OK |
|
|
670
|
+
| Just sorting once | Array.sort() | O(n log n) | One-time cost OK |
|
|
671
|
+
|
|
672
|
+
### Quick Decision Guide
|
|
673
|
+
|
|
674
|
+
```
|
|
675
|
+
Need frequent head/tail operations?
|
|
676
|
+
YES → Deque (O(1) shift/unshift/push/pop)
|
|
677
|
+
NO → Next
|
|
678
|
+
|
|
679
|
+
Need sorted + fast lookup?
|
|
680
|
+
YES → RedBlackTree (O(log n) guaranteed)
|
|
681
|
+
NO → Next
|
|
682
|
+
|
|
683
|
+
Need highest/lowest priority?
|
|
684
|
+
YES → Heap/PriorityQueue (O(log n) add/remove)
|
|
685
|
+
NO → Next
|
|
686
|
+
|
|
687
|
+
Need prefix/text matching?
|
|
688
|
+
YES → Trie (O(m+k) where m=prefix)
|
|
689
|
+
NO → Next
|
|
690
|
+
|
|
691
|
+
Need graph operations?
|
|
692
|
+
YES → DirectedGraph/UndirectedGraph
|
|
693
|
+
NO → Use Array (simplest case)
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
---
|
|
697
|
+
|
|
698
|
+
## Optimization Tips
|
|
699
|
+
|
|
700
|
+
### Tip 1: Batch Operations
|
|
701
|
+
|
|
702
|
+
```javascript
|
|
703
|
+
// ❌ Slow: Sorting after each insert
|
|
704
|
+
const tree = new RedBlackTree();
|
|
705
|
+
for (const item of items) {
|
|
706
|
+
tree.set(item.id, item); // Tree rebalances each time
|
|
707
|
+
}
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
```javascript
|
|
711
|
+
// ✅ Fast: Build in bulk
|
|
712
|
+
const tree = new RedBlackTree(items);
|
|
713
|
+
// Single rebalancing pass
|
|
714
|
+
|
|
715
|
+
// Often faster for large datasets (fewer per-insert balancing steps). Measure on your workload.
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
### Tip 2: Use Right Structure Early
|
|
719
|
+
|
|
720
|
+
```javascript
|
|
721
|
+
// ❌ Wrong: Start with Array, convert later
|
|
722
|
+
const data = [];
|
|
723
|
+
for (const item of input) data.push(item);
|
|
724
|
+
const sorted = [...new RedBlackTree(data).keys()];
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
```javascript
|
|
728
|
+
// ✅ Right: Use correct structure immediately
|
|
729
|
+
const tree = new RedBlackTree(input);
|
|
730
|
+
const sorted = [...tree.keys()];
|
|
731
|
+
|
|
732
|
+
// Benefit: No conversion overhead
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
### Tip 3: Chain Operations
|
|
736
|
+
|
|
737
|
+
```javascript
|
|
738
|
+
// ❌ Slow: Converting to Array loses benefits
|
|
739
|
+
const tree = new RedBlackTree(data);
|
|
740
|
+
const result = tree.toArray()
|
|
741
|
+
.filter(x => x > 5)
|
|
742
|
+
.map(x => x * 2);
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
```javascript
|
|
746
|
+
// ✅ Fast: Stay on tree
|
|
747
|
+
const result = tree
|
|
748
|
+
.filter((v => (v ?? 0) > 5)
|
|
749
|
+
.map(((v, k) => [k, (x ?? 0) * 2]);
|
|
750
|
+
|
|
751
|
+
// Benefit: Maintains structure type throughout
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### Tip 4: V8 JIT Warm-up
|
|
755
|
+
|
|
756
|
+
```javascript
|
|
757
|
+
// First calls are interpreted (slow)
|
|
758
|
+
// Subsequent calls are JIT-compiled (fast)
|
|
759
|
+
|
|
760
|
+
const tree = new RedBlackTree();
|
|
761
|
+
|
|
762
|
+
// First 100 inserts: Interpreted, slower
|
|
763
|
+
// Next 900 inserts: JIT-compiled (typically faster)
|
|
764
|
+
|
|
765
|
+
// Strategy: Do warm-up before timing
|
|
766
|
+
for (let i = 0; i < 1000; i++) tree.set(i, i);
|
|
767
|
+
// Now tree is warm and fast for benchmarks
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### Tip 5: Choose Right Comparator
|
|
771
|
+
|
|
772
|
+
```javascript
|
|
773
|
+
// ❌ Slow: Complex comparator
|
|
774
|
+
const tree = new RedBlackTree((a, b) => {
|
|
775
|
+
if (a.category !== b.category) {
|
|
776
|
+
return a.category.localeCompare(b.category);
|
|
777
|
+
}
|
|
778
|
+
return a.priority - b.priority;
|
|
779
|
+
});
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
```javascript
|
|
783
|
+
// ✅ Fast: Simple comparator
|
|
784
|
+
const tree = new RedBlackTree([], { comparator: (a, b) => a - b)
|
|
785
|
+
}
|
|
786
|
+
;
|
|
787
|
+
|
|
788
|
+
// Why: V8 can inline simple comparators
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
---
|
|
792
|
+
|
|
793
|
+
## Benchmark Summary Table
|
|
794
|
+
|
|
795
|
+
### Operations per Second
|
|
796
|
+
|
|
797
|
+
| Operation | Array | Deque | Tree | Heap |
|
|
798
|
+
|-------------|---------|----------|-----------|--------|
|
|
799
|
+
| 1K shifts | 353/sec | 171K/sec | - | - |
|
|
800
|
+
| 1K inserts | 625/sec | 625/sec | 10K/sec | 8K/sec |
|
|
801
|
+
| 1K searches | 2K/sec | - | 100K/sec | 1K/sec |
|
|
802
|
+
| 1K sorts | 1/sec | - | 1000/sec* | - |
|
|
803
|
+
|
|
804
|
+
*Maintains sorted order
|
|
805
|
+
|
|
806
|
+
---
|
|
807
|
+
|
|
808
|
+
## Conclusion
|
|
809
|
+
|
|
810
|
+
### When to Optimize
|
|
811
|
+
|
|
812
|
+
1. **Profile first**: Don't optimize without data
|
|
813
|
+
2. **Hot paths only**: Focus on frequently-called code
|
|
814
|
+
3. **Right structure matters**: large speedups are possible (see the measured scenarios above)
|
|
815
|
+
4. **Small datasets**: Array usually fine
|
|
816
|
+
5. **Large datasets**: Structure choice critical
|
|
817
|
+
|
|
818
|
+
### Performance Hierarchy
|
|
819
|
+
|
|
820
|
+
```
|
|
821
|
+
Array.sort() ← Simple, once per session
|
|
822
|
+
RedBlackTree ← Sorted + frequent updates
|
|
823
|
+
Deque ← Frequent head/tail ops
|
|
824
|
+
Heap ← Priority matters
|
|
825
|
+
Trie ← Prefix search
|
|
826
|
+
HashMap/Map ← Unsorted key-value lookup
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
---
|
|
830
|
+
|
|
831
|
+
**Need examples?** See [GUIDES.md](/guide/guides.md).
|
|
832
|
+
|
|
833
|
+
**Understand why?** Read [ARCHITECTURE.md](/guide/architecture.md).
|