test: Competitor Performance Comparison Test

This commit is contained in:
Revone 2023-11-11 00:17:50 +08:00
parent cffe084c2b
commit 7bcb0ba843
11 changed files with 180 additions and 15 deletions

View file

@ -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

View file

@ -728,40 +728,40 @@ optimal approach to data structure design.
[//]: # (No deletion!!! Start of Replace Section)
<div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>33.60</td><td>29.76</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>72.39</td><td>13.81</td><td>0.01</td></tr><tr><td>10,000 addMany</td><td>41.06</td><td>24.35</td><td>0.00</td></tr><tr><td>10,000 get</td><td>28.01</td><td>35.71</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>32.23</td><td>31.03</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>72.19</td><td>13.85</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>41.39</td><td>24.16</td><td>9.33e-4</td></tr><tr><td>10,000 get</td><td>28.05</td><td>35.66</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>binary-tree</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 add randomly</td><td>12.64</td><td>79.09</td><td>6.90e-4</td></tr><tr><td>1,000 add & delete randomly</td><td>16.03</td><td>62.38</td><td>5.30e-4</td></tr><tr><td>1,000 addMany</td><td>10.44</td><td>95.78</td><td>0.00</td></tr><tr><td>1,000 get</td><td>18.19</td><td>54.98</td><td>3.11e-4</td></tr><tr><td>1,000 dfs</td><td>154.71</td><td>6.46</td><td>0.00</td></tr><tr><td>1,000 bfs</td><td>56.97</td><td>17.55</td><td>8.92e-4</td></tr><tr><td>1,000 morris</td><td>260.71</td><td>3.84</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 add randomly</td><td>12.56</td><td>79.59</td><td>6.46e-4</td></tr><tr><td>1,000 add & delete randomly</td><td>16.15</td><td>61.91</td><td>7.18e-4</td></tr><tr><td>1,000 addMany</td><td>10.64</td><td>93.95</td><td>6.17e-4</td></tr><tr><td>1,000 get</td><td>18.44</td><td>54.22</td><td>4.23e-4</td></tr><tr><td>1,000 dfs</td><td>160.17</td><td>6.24</td><td>0.01</td></tr><tr><td>1,000 bfs</td><td>57.41</td><td>17.42</td><td>0.00</td></tr><tr><td>1,000 morris</td><td>264.54</td><td>3.78</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>bst</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>29.57</td><td>33.81</td><td>2.75e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>70.78</td><td>14.13</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>29.10</td><td>34.36</td><td>6.84e-4</td></tr><tr><td>10,000 get</td><td>28.75</td><td>34.78</td><td>6.05e-4</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>28.45</td><td>35.15</td><td>4.14e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>67.78</td><td>14.75</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>29.04</td><td>34.43</td><td>5.76e-4</td></tr><tr><td>10,000 get</td><td>28.67</td><td>34.88</td><td>8.26e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>rb-tree</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add randomly</td><td>88.55</td><td>11.29</td><td>0.01</td></tr><tr><td>100,000 add & delete randomly</td><td>220.41</td><td>4.54</td><td>0.01</td></tr><tr><td>100,000 getNode</td><td>37.52</td><td>26.65</td><td>2.68e-4</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add randomly</td><td>90.96</td><td>10.99</td><td>0.01</td></tr><tr><td>100,000 competitor add randomly</td><td>50.10</td><td>19.96</td><td>0.01</td></tr><tr><td>100,000 add & delete randomly</td><td>219.06</td><td>4.56</td><td>0.01</td></tr><tr><td>100,000 getNode</td><td>106.06</td><td>9.43</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.10</td><td>9804.12</td><td>1.07e-6</td></tr><tr><td>1,000 addEdge</td><td>6.06</td><td>165.11</td><td>1.66e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>3.48e-7</td></tr><tr><td>1,000 getEdge</td><td>23.26</td><td>43.00</td><td>0.00</td></tr><tr><td>tarjan</td><td>223.27</td><td>4.48</td><td>0.01</td></tr><tr><td>tarjan all</td><td>224.27</td><td>4.46</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>179.19</td><td>5.58</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.11</td><td>9433.92</td><td>4.40e-6</td></tr><tr><td>1,000 addEdge</td><td>6.24</td><td>160.30</td><td>2.02e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.13e+4</td><td>1.64e-6</td></tr><tr><td>1,000 getEdge</td><td>23.80</td><td>42.02</td><td>0.00</td></tr><tr><td>tarjan</td><td>218.46</td><td>4.58</td><td>0.01</td></tr><tr><td>tarjan all</td><td>221.95</td><td>4.51</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>183.70</td><td>5.44</td><td>0.01</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add & pop</td><td>4.62</td><td>216.39</td><td>3.75e-5</td></tr><tr><td>10,000 fib add & pop</td><td>354.57</td><td>2.82</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add & pop</td><td>4.63</td><td>215.97</td><td>4.50e-5</td></tr><tr><td>10,000 fib add & pop</td><td>359.98</td><td>2.78</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 unshift</td><td>225.57</td><td>4.43</td><td>0.02</td></tr><tr><td>1,000,000 unshift & shift</td><td>164.91</td><td>6.06</td><td>0.02</td></tr><tr><td>1,000,000 insertBefore</td><td>342.06</td><td>2.92</td><td>0.09</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 unshift</td><td>233.68</td><td>4.28</td><td>0.06</td></tr><tr><td>1,000,000 unshift & shift</td><td>185.63</td><td>5.39</td><td>0.05</td></tr><tr><td>1,000,000 insertBefore</td><td>321.19</td><td>3.11</td><td>0.04</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 push & pop</td><td>224.20</td><td>4.46</td><td>0.02</td></tr><tr><td>10,000 insertBefore</td><td>244.96</td><td>4.08</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 push & pop</td><td>217.95</td><td>4.59</td><td>0.01</td></tr><tr><td>10,000 insertBefore</td><td>248.81</td><td>4.02</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>max-priority-queue</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 refill & poll</td><td>11.45</td><td>87.32</td><td>1.74e-4</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 refill & poll</td><td>11.72</td><td>85.30</td><td>2.79e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>222.74</td><td>4.49</td><td>0.08</td></tr><tr><td>1,000,000 shift</td><td>26.48</td><td>37.77</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>204.13</td><td>4.90</td><td>0.04</td></tr><tr><td>1,000,000 shift</td><td>25.71</td><td>38.89</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>45.50</td><td>21.98</td><td>0.01</td></tr><tr><td>1,000,000 push & shift</td><td>80.10</td><td>12.48</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>42.93</td><td>23.30</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>80.12</td><td>12.48</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>56.99</td><td>17.55</td><td>0.01</td></tr><tr><td>100,000 getWords</td><td>98.43</td><td>10.16</td><td>0.01</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>56.09</td><td>17.83</td><td>0.00</td></tr><tr><td>100,000 getWords</td><td>97.76</td><td>10.23</td><td>0.01</td></tr></table></div>
</div>
[//]: # (No deletion!!! End of Replace Section)

15
package-lock.json generated
View file

@ -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",

View file

@ -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",

View file

@ -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<number, number>();
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++) {

View file

@ -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<number, number>();
for (let i = 0; i < LINEAR; i++) {
hm.set(i, i);
}
})
.add(`${LINEAR.toLocaleString()} competitor set`, () => {
const hm = new CHashMap<number, number>();
for (let i = 0; i < LINEAR; i++) {
hm.setElement(i, i);
}
})
.add(`${LINEAR.toLocaleString()} set & get`, () => {
const hm = new HashMap<number, number>();
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<number, number>();
for (let i = 0; i < LINEAR; i++) {
hm.setElement(i, i);
}
for (let i = 0; i < LINEAR; i++) {
hm.getElementByKey(i);
}
});
export {suite};

View file

@ -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<number>();
for (let i = 0; i < LINEAR; i++) {
list.pushFront(i);
}
})
.add(`${LINEAR.toLocaleString()} unshift & shift`, () => {
const list = new DoublyLinkedList<number>();

View file

@ -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<number>({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<number>();
for (let i = 0; i < TEN_THOUSAND; i++) {
pq.push(i);
}
for (let i = 0; i < TEN_THOUSAND; i++) {
pq.pop();
}
});
export {suite};

View file

@ -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<number>();
for (let i = 0; i < LINEAR; i++) {
deque.pushBack(i);
}
})
.add(`${LINEAR.toLocaleString()} shift`, () => {
const deque = new Deque<number>();
for (let i = 0; i < LINEAR; i++) {

View file

@ -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<number>();
for (let i = 0; i < LINEAR; i++) {
queue.push(i);
}
})
.add(`${LINEAR.toLocaleString()} push & shift`, () => {
const queue = new Queue<number>();

View file

@ -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<number>();
for (let i = 0; i < LINEAR; i++) {
stack.push(i);
}
})
.add(`${LINEAR.toLocaleString()} competitor push`, () => {
const queue = new CStack<number>();
for (let i = 0; i < LINEAR; i++) {
queue.push(i);
}
})
.add(`${LINEAR.toLocaleString()} push & pop`, () => {
const queue = new Stack<number>();
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<number>();
for (let i = 0; i < LINEAR; i++) {
queue.push(i);
}
for (let i = 0; i < LINEAR; i++) {
queue.pop();
}
});
export {suite};