diff --git a/CHANGELOG.md b/CHANGELOG.md index 8866bc1..5a6c379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.42.9](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) +## [v1.43.0](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) ### Changes diff --git a/README.md b/README.md index 6947dea..9f977bb 100644 --- a/README.md +++ b/README.md @@ -728,40 +728,40 @@ optimal approach to data structure design. [//]: # (No deletion!!! Start of Replace Section)
avl-tree
-
test nametime taken (ms)executions per secsample deviation
10,000 add randomly33.6029.760.00
10,000 add & delete randomly72.3913.810.01
10,000 addMany41.0624.350.00
10,000 get28.0135.710.00
+
test nametime taken (ms)executions per secsample deviation
10,000 add randomly32.2331.030.00
10,000 add & delete randomly72.1913.850.00
10,000 addMany41.3924.169.33e-4
10,000 get28.0535.660.00
binary-tree
-
test nametime taken (ms)executions per secsample deviation
1,000 add randomly12.6479.096.90e-4
1,000 add & delete randomly16.0362.385.30e-4
1,000 addMany10.4495.780.00
1,000 get18.1954.983.11e-4
1,000 dfs154.716.460.00
1,000 bfs56.9717.558.92e-4
1,000 morris260.713.840.00
+
test nametime taken (ms)executions per secsample deviation
1,000 add randomly12.5679.596.46e-4
1,000 add & delete randomly16.1561.917.18e-4
1,000 addMany10.6493.956.17e-4
1,000 get18.4454.224.23e-4
1,000 dfs160.176.240.01
1,000 bfs57.4117.420.00
1,000 morris264.543.780.00
bst
-
test nametime taken (ms)executions per secsample deviation
10,000 add randomly29.5733.812.75e-4
10,000 add & delete randomly70.7814.130.00
10,000 addMany29.1034.366.84e-4
10,000 get28.7534.786.05e-4
+
test nametime taken (ms)executions per secsample deviation
10,000 add randomly28.4535.154.14e-4
10,000 add & delete randomly67.7814.750.00
10,000 addMany29.0434.435.76e-4
10,000 get28.6734.888.26e-4
rb-tree
-
test nametime taken (ms)executions per secsample deviation
100,000 add randomly88.5511.290.01
100,000 add & delete randomly220.414.540.01
100,000 getNode37.5226.652.68e-4
+
test nametime taken (ms)executions per secsample deviation
100,000 add randomly90.9610.990.01
100,000 competitor add randomly50.1019.960.01
100,000 add & delete randomly219.064.560.01
100,000 getNode106.069.430.00
directed-graph
-
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.109804.121.07e-6
1,000 addEdge6.06165.111.66e-4
1,000 getVertex0.052.17e+43.48e-7
1,000 getEdge23.2643.000.00
tarjan223.274.480.01
tarjan all224.274.460.00
topologicalSort179.195.580.00
+
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.119433.924.40e-6
1,000 addEdge6.24160.302.02e-4
1,000 getVertex0.052.13e+41.64e-6
1,000 getEdge23.8042.020.00
tarjan218.464.580.01
tarjan all221.954.510.00
topologicalSort183.705.440.01
heap
-
test nametime taken (ms)executions per secsample deviation
10,000 add & pop4.62216.393.75e-5
10,000 fib add & pop354.572.820.00
+
test nametime taken (ms)executions per secsample deviation
10,000 add & pop4.63215.974.50e-5
10,000 fib add & pop359.982.780.00
doubly-linked-list
-
test nametime taken (ms)executions per secsample deviation
1,000,000 unshift225.574.430.02
1,000,000 unshift & shift164.916.060.02
1,000,000 insertBefore342.062.920.09
+
test nametime taken (ms)executions per secsample deviation
1,000,000 unshift233.684.280.06
1,000,000 unshift & shift185.635.390.05
1,000,000 insertBefore321.193.110.04
singly-linked-list
-
test nametime taken (ms)executions per secsample deviation
10,000 push & pop224.204.460.02
10,000 insertBefore244.964.080.00
+
test nametime taken (ms)executions per secsample deviation
10,000 push & pop217.954.590.01
10,000 insertBefore248.814.020.00
max-priority-queue
-
test nametime taken (ms)executions per secsample deviation
10,000 refill & poll11.4587.321.74e-4
+
test nametime taken (ms)executions per secsample deviation
10,000 refill & poll11.7285.302.79e-4
deque
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push222.744.490.08
1,000,000 shift26.4837.770.00
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push204.134.900.04
1,000,000 shift25.7138.890.00
queue
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push45.5021.980.01
1,000,000 push & shift80.1012.480.00
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push42.9323.300.00
1,000,000 push & shift80.1212.480.00
trie
-
test nametime taken (ms)executions per secsample deviation
100,000 push56.9917.550.01
100,000 getWords98.4310.160.01
+
test nametime taken (ms)executions per secsample deviation
100,000 push56.0917.830.00
100,000 getWords97.7610.230.01
[//]: # (No deletion!!! End of Replace Section) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c0faebd..6915fd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.42.5", + "version": "1.43.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.42.5", + "version": "1.43.0", "license": "MIT", "devDependencies": { "@types/benchmark": "^2.1.3", @@ -30,6 +30,7 @@ "heap-typed": "^1.42.5", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", + "js-sdsl": "^4.4.2", "prettier": "^3.0.3", "ts-jest": "^29.1.1", "ts-loader": "^9.4.4", @@ -6628,6 +6629,16 @@ "node": ">=10" } }, + "node_modules/js-sdsl": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.2.tgz", + "integrity": "sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==", + "dev": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index e464d1b..ca7ae2a 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "heap-typed": "^1.42.5", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", + "js-sdsl": "^4.4.2", "prettier": "^3.0.3", "ts-jest": "^29.1.1", "ts-loader": "^9.4.4", diff --git a/test/performance/data-structures/binary-tree/rb-tree.test.ts b/test/performance/data-structures/binary-tree/rb-tree.test.ts index 34b4532..2eb72f9 100644 --- a/test/performance/data-structures/binary-tree/rb-tree.test.ts +++ b/test/performance/data-structures/binary-tree/rb-tree.test.ts @@ -1,11 +1,13 @@ import {RedBlackTree} from '../../../../src'; import * as Benchmark from 'benchmark'; import {getRandomIntArray, magnitude} from '../../../utils'; +import {OrderedMap} from 'js-sdsl'; const suite = new Benchmark.Suite(); const rbTree = new RedBlackTree(); const {HUNDRED_THOUSAND} = magnitude; const arr = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true); +const competitor = new OrderedMap(); suite .add(`${HUNDRED_THOUSAND.toLocaleString()} add randomly`, () => { @@ -14,6 +16,11 @@ suite rbTree.add(arr[i]); } }) + .add(`${HUNDRED_THOUSAND.toLocaleString()} competitor add randomly`, () => { + for (let i = 0; i < arr.length; i++) { + competitor.setElement(arr[i], arr[i]); + } + }) .add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete randomly`, () => { rbTree.clear(); for (let i = 0; i < arr.length; i++) { diff --git a/test/performance/data-structures/hash/hash-map.test.ts b/test/performance/data-structures/hash/hash-map.test.ts index e69de29..703b76f 100644 --- a/test/performance/data-structures/hash/hash-map.test.ts +++ b/test/performance/data-structures/hash/hash-map.test.ts @@ -0,0 +1,45 @@ +import {HashMap} from '../../../../src'; +import {HashMap as CHashMap} from 'js-sdsl'; +import * as Benchmark from 'benchmark'; +import {magnitude} from '../../../utils'; + +const suite = new Benchmark.Suite(); +const {LINEAR} = magnitude; + +suite + .add(`${LINEAR.toLocaleString()} set`, () => { + const hm = new HashMap(); + + for (let i = 0; i < LINEAR; i++) { + hm.set(i, i); + } + }) + .add(`${LINEAR.toLocaleString()} competitor set`, () => { + const hm = new CHashMap(); + + for (let i = 0; i < LINEAR; i++) { + hm.setElement(i, i); + } + }) + .add(`${LINEAR.toLocaleString()} set & get`, () => { + const hm = new HashMap(); + + for (let i = 0; i < LINEAR; i++) { + hm.set(i, i); + } + for (let i = 0; i < LINEAR; i++) { + hm.get(i); + } + }) + .add(`${LINEAR.toLocaleString()} competitor set & get`, () => { + const hm = new CHashMap(); + + for (let i = 0; i < LINEAR; i++) { + hm.setElement(i, i); + } + for (let i = 0; i < LINEAR; i++) { + hm.getElementByKey(i); + } + }); + +export {suite}; diff --git a/test/performance/data-structures/linked-list/doubly-linked-list.test.ts b/test/performance/data-structures/linked-list/doubly-linked-list.test.ts index 5cc9977..3911fd9 100644 --- a/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +++ b/test/performance/data-structures/linked-list/doubly-linked-list.test.ts @@ -1,4 +1,5 @@ import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src'; +import {LinkList as CLinkedList} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; @@ -13,6 +14,13 @@ suite list.unshift(i); } }) + .add(`${LINEAR.toLocaleString()} competitor unshift`, () => { + const list = new CLinkedList(); + + for (let i = 0; i < LINEAR; i++) { + list.pushFront(i); + } + }) .add(`${LINEAR.toLocaleString()} unshift & shift`, () => { const list = new DoublyLinkedList(); diff --git a/test/performance/data-structures/priority-queue/priority-queue.test.ts b/test/performance/data-structures/priority-queue/priority-queue.test.ts index e69de29..04808f2 100644 --- a/test/performance/data-structures/priority-queue/priority-queue.test.ts +++ b/test/performance/data-structures/priority-queue/priority-queue.test.ts @@ -0,0 +1,33 @@ +import {PriorityQueue as CPriorityQueue} from 'js-sdsl'; +import {PriorityQueue} from '../../../../src'; +import * as Benchmark from 'benchmark'; +import {magnitude} from '../../../utils'; + +const suite = new Benchmark.Suite(); +const {TEN_THOUSAND} = magnitude; + +suite + .add(`${TEN_THOUSAND.toLocaleString()} add & pop`, () => { + const pq = new PriorityQueue({comparator: (a, b) => b - a}); + + for (let i = 0; i < TEN_THOUSAND; i++) { + pq.add(i); + } + + for (let i = 0; i < TEN_THOUSAND; i++) { + pq.pop(); + } + }) + .add(`${TEN_THOUSAND.toLocaleString()} competitor add & pop`, () => { + const pq = new CPriorityQueue(); + + for (let i = 0; i < TEN_THOUSAND; i++) { + pq.push(i); + } + + for (let i = 0; i < TEN_THOUSAND; i++) { + pq.pop(); + } + }); + +export {suite}; diff --git a/test/performance/data-structures/queue/deque.test.ts b/test/performance/data-structures/queue/deque.test.ts index 566b370..a0bde90 100644 --- a/test/performance/data-structures/queue/deque.test.ts +++ b/test/performance/data-structures/queue/deque.test.ts @@ -1,4 +1,5 @@ import {Deque} from '../../../../src'; +import {Deque as CDeque} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; @@ -12,6 +13,12 @@ suite deque.push(i); } }) + .add(`${LINEAR.toLocaleString()} competitor push`, () => { + const deque = new CDeque(); + for (let i = 0; i < LINEAR; i++) { + deque.pushBack(i); + } + }) .add(`${LINEAR.toLocaleString()} shift`, () => { const deque = new Deque(); for (let i = 0; i < LINEAR; i++) { diff --git a/test/performance/data-structures/queue/queue.test.ts b/test/performance/data-structures/queue/queue.test.ts index a5b5874..93e32a2 100644 --- a/test/performance/data-structures/queue/queue.test.ts +++ b/test/performance/data-structures/queue/queue.test.ts @@ -1,4 +1,5 @@ import {Queue} from '../../../../src'; +import {Queue as CQueue} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; @@ -13,6 +14,13 @@ suite queue.push(i); } }) + .add(`${LINEAR.toLocaleString()} competitor push`, () => { + const queue = new CQueue(); + + for (let i = 0; i < LINEAR; i++) { + queue.push(i); + } + }) .add(`${LINEAR.toLocaleString()} push & shift`, () => { const queue = new Queue(); diff --git a/test/performance/data-structures/stack/stack.test.ts b/test/performance/data-structures/stack/stack.test.ts index e69de29..ec3c24d 100644 --- a/test/performance/data-structures/stack/stack.test.ts +++ b/test/performance/data-structures/stack/stack.test.ts @@ -0,0 +1,45 @@ +import {Stack} from '../../../../src'; +import {Stack as CStack} from 'js-sdsl'; +import * as Benchmark from 'benchmark'; +import {magnitude} from '../../../utils'; + +const suite = new Benchmark.Suite(); +const {LINEAR} = magnitude; + +suite + .add(`${LINEAR.toLocaleString()} push`, () => { + const stack = new Stack(); + + for (let i = 0; i < LINEAR; i++) { + stack.push(i); + } + }) + .add(`${LINEAR.toLocaleString()} competitor push`, () => { + const queue = new CStack(); + + for (let i = 0; i < LINEAR; i++) { + queue.push(i); + } + }) + .add(`${LINEAR.toLocaleString()} push & pop`, () => { + const queue = new Stack(); + + for (let i = 0; i < LINEAR; i++) { + queue.push(i); + } + for (let i = 0; i < LINEAR; i++) { + queue.pop(); + } + }) + .add(`${LINEAR.toLocaleString()} competitor push & pop`, () => { + const queue = new CStack(); + + for (let i = 0; i < LINEAR; i++) { + queue.push(i); + } + for (let i = 0; i < LINEAR; i++) { + queue.pop(); + } + }); + +export {suite};