test: Added a switch to control whether to test the performance of competitors.

This commit is contained in:
Revone 2023-11-11 09:59:11 +08:00
parent 7bcb0ba843
commit c985317259
10 changed files with 129 additions and 89 deletions

View file

@ -728,40 +728,49 @@ 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>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 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>31.34</td><td>31.90</td><td>3.63e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>71.68</td><td>13.95</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>48.63</td><td>20.56</td><td>0.01</td></tr><tr><td>10,000 get</td><td>28.99</td><td>34.49</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.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 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.47</td><td>80.21</td><td>2.46e-4</td></tr><tr><td>1,000 add & delete randomly</td><td>16.29</td><td>61.39</td><td>0.00</td></tr><tr><td>1,000 addMany</td><td>10.34</td><td>96.67</td><td>1.78e-4</td></tr><tr><td>1,000 get</td><td>22.72</td><td>44.02</td><td>0.01</td></tr><tr><td>1,000 dfs</td><td>167.13</td><td>5.98</td><td>0.01</td></tr><tr><td>1,000 bfs</td><td>57.06</td><td>17.53</td><td>4.63e-4</td></tr><tr><td>1,000 morris</td><td>272.80</td><td>3.67</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'>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>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 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>30.28</td><td>33.02</td><td>4.41e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>73.93</td><td>13.53</td><td>0.01</td></tr><tr><td>10,000 addMany</td><td>29.66</td><td>33.72</td><td>0.00</td></tr><tr><td>10,000 get</td><td>27.96</td><td>35.76</td><td>3.35e-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>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 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>89.26</td><td>11.20</td><td>0.01</td></tr><tr><td>100,000 add & delete randomly</td><td>218.90</td><td>4.57</td><td>0.01</td></tr><tr><td>100,000 getNode</td><td>41.74</td><td>23.96</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.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 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>9995.32</td><td>1.43e-6</td></tr><tr><td>1,000 addEdge</td><td>6.32</td><td>158.28</td><td>7.89e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>2.66e-7</td></tr><tr><td>1,000 getEdge</td><td>23.68</td><td>42.23</td><td>0.00</td></tr><tr><td>tarjan</td><td>214.15</td><td>4.67</td><td>0.01</td></tr><tr><td>tarjan all</td><td>214.51</td><td>4.66</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>182.64</td><td>5.48</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'>hash-map</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 set</td><td>16.51</td><td>60.57</td><td>9.87e-4</td></tr><tr><td>10,000 set & get</td><td>34.75</td><td>28.77</td><td>6.11e-4</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.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 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.34</td><td>4.19e-5</td></tr><tr><td>10,000 fib add & pop</td><td>358.77</td><td>2.79</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>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 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>232.43</td><td>4.30</td><td>0.09</td></tr><tr><td>1,000,000 unshift & shift</td><td>174.59</td><td>5.73</td><td>0.05</td></tr><tr><td>1,000,000 insertBefore</td><td>322.71</td><td>3.10</td><td>0.07</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>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 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>216.35</td><td>4.62</td><td>0.01</td></tr><tr><td>10,000 insertBefore</td><td>246.91</td><td>4.05</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.72</td><td>85.30</td><td>2.79e-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.67</td><td>85.71</td><td>2.89e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>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 add & pop</td><td>12.43</td><td>80.44</td><td>1.15e-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>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 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.16</td><td>4.50</td><td>0.06</td></tr><tr><td>1,000,000 shift</td><td>26.33</td><td>37.98</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>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 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.99</td><td>21.74</td><td>0.01</td></tr><tr><td>1,000,000 push & shift</td><td>80.49</td><td>12.42</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'>stack</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>44.04</td><td>22.71</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>50.06</td><td>19.98</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'>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.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 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>44.87</td><td>22.29</td><td>7.28e-4</td></tr><tr><td>100,000 getWords</td><td>88.45</td><td>11.31</td><td>0.00</td></tr></table></div>
</div>
[//]: # (No deletion!!! End of Replace Section)

View file

@ -33,7 +33,7 @@
"install:all-subs": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multimap-typed trie-typed undirected-graph-typed queue-typed --save-dev",
"test": "jest --runInBand",
"test:integration": "npm run update:subs && jest --config jest.integration.config.js",
"benchmark": "ts-node test/performance/reportor.ts",
"test:perf": "ts-node test/performance/reportor.ts",
"check:deps": "dependency-cruiser src",
"changelog": "auto-changelog",
"coverage:badge": "istanbul-badges-readme",

View file

@ -1 +1,2 @@
export const isDebugTest = false;
export const isCompetitor = false;

View file

@ -2,6 +2,7 @@ import {RedBlackTree} from '../../../../src';
import * as Benchmark from 'benchmark';
import {getRandomIntArray, magnitude} from '../../../utils';
import {OrderedMap} from 'js-sdsl';
import {isCompetitor} from "../../../config";
const suite = new Benchmark.Suite();
const rbTree = new RedBlackTree();
@ -15,21 +16,26 @@ suite
for (let i = 0; i < arr.length; i++) {
rbTree.add(arr[i]);
}
})
.add(`${HUNDRED_THOUSAND.toLocaleString()} competitor add randomly`, () => {
});
if (isCompetitor) {
suite.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++) {
rbTree.add(arr[i]);
}
for (let i = 0; i < arr.length; i++) {
rbTree.delete(arr[i]);
}
})
}
suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete randomly`, () => {
rbTree.clear();
for (let i = 0; i < arr.length; i++) {
rbTree.add(arr[i]);
}
for (let i = 0; i < arr.length; i++) {
rbTree.delete(arr[i]);
}
})
.add(`${HUNDRED_THOUSAND.toLocaleString()} getNode`, () => {
for (let i = 0; i < arr.length; i++) {
rbTree.getNode(arr[i]);

View file

@ -2,44 +2,50 @@ import {HashMap} from '../../../../src';
import {HashMap as CHashMap} from 'js-sdsl';
import * as Benchmark from 'benchmark';
import {magnitude} from '../../../utils';
import {isCompetitor} from "../../../config";
const suite = new Benchmark.Suite();
const {LINEAR} = magnitude;
const {TEN_THOUSAND} = magnitude;
suite
.add(`${LINEAR.toLocaleString()} set`, () => {
.add(`${TEN_THOUSAND.toLocaleString()} set`, () => {
const hm = new HashMap<number, number>();
for (let i = 0; i < LINEAR; i++) {
for (let i = 0; i < TEN_THOUSAND; 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);
}
});
if (isCompetitor) {
suite.add(`${TEN_THOUSAND.toLocaleString()} competitor set`, () => {
const hm = new CHashMap<number, number>();
for (let i = 0; i < TEN_THOUSAND; i++) {
hm.setElement(i, i);
}
})
}
suite.add(`${TEN_THOUSAND.toLocaleString()} set & get`, () => {
const hm = new HashMap<number, number>();
for (let i = 0; i < TEN_THOUSAND; i++) {
hm.set(i, i);
}
for (let i = 0; i < TEN_THOUSAND; i++) {
hm.get(i);
}
})
;
if (isCompetitor) {
suite.add(`${TEN_THOUSAND.toLocaleString()} competitor set & get`, () => {
const hm = new CHashMap<number, number>();
for (let i = 0; i < TEN_THOUSAND; i++) {
hm.setElement(i, i);
}
for (let i = 0; i < TEN_THOUSAND; i++) {
hm.getElementByKey(i);
}
})
}
export {suite};

View file

@ -2,6 +2,7 @@ import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
import {LinkList as CLinkedList} from 'js-sdsl';
import * as Benchmark from 'benchmark';
import {magnitude} from '../../../utils';
import {isCompetitor} from "../../../config";
const suite = new Benchmark.Suite();
const {LINEAR} = magnitude;
@ -14,14 +15,16 @@ suite
list.unshift(i);
}
})
.add(`${LINEAR.toLocaleString()} competitor unshift`, () => {
const list = new CLinkedList<number>();
if (isCompetitor) {
suite.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`, () => {
for (let i = 0; i < LINEAR; i++) {
list.pushFront(i);
}
})
}
suite.add(`${LINEAR.toLocaleString()} unshift & shift`, () => {
const list = new DoublyLinkedList<number>();
for (let i = 0; i < LINEAR; i++) {

View file

@ -2,6 +2,7 @@ import {PriorityQueue as CPriorityQueue} from 'js-sdsl';
import {PriorityQueue} from '../../../../src';
import * as Benchmark from 'benchmark';
import {magnitude} from '../../../utils';
import {isCompetitor} from "../../../config";
const suite = new Benchmark.Suite();
const {TEN_THOUSAND} = magnitude;
@ -17,8 +18,9 @@ suite
for (let i = 0; i < TEN_THOUSAND; i++) {
pq.pop();
}
})
.add(`${TEN_THOUSAND.toLocaleString()} competitor add & pop`, () => {
});
if (isCompetitor) {
suite.add(`${TEN_THOUSAND.toLocaleString()} competitor add & pop`, () => {
const pq = new CPriorityQueue<number>();
for (let i = 0; i < TEN_THOUSAND; i++) {
@ -30,4 +32,6 @@ suite
}
});
}
export {suite};

View file

@ -2,6 +2,7 @@ import {Deque} from '../../../../src';
import {Deque as CDeque} from 'js-sdsl';
import * as Benchmark from 'benchmark';
import {magnitude} from '../../../utils';
import {isCompetitor} from "../../../config";
export const suite = new Benchmark.Suite();
const {LINEAR} = magnitude;
@ -13,13 +14,15 @@ 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`, () => {
if (isCompetitor) {
suite.add(`${LINEAR.toLocaleString()} competitor push`, () => {
const deque = new CDeque<number>();
for (let i = 0; i < LINEAR; i++) {
deque.pushBack(i);
}
})
}
suite.add(`${LINEAR.toLocaleString()} shift`, () => {
const deque = new Deque<number>();
for (let i = 0; i < LINEAR; i++) {
deque.push(i);

View file

@ -2,6 +2,7 @@ import {Queue} from '../../../../src';
import {Queue as CQueue} from 'js-sdsl';
import * as Benchmark from 'benchmark';
import {magnitude} from '../../../utils';
import {isCompetitor} from "../../../config";
const suite = new Benchmark.Suite();
const {LINEAR} = magnitude;
@ -14,14 +15,16 @@ suite
queue.push(i);
}
})
.add(`${LINEAR.toLocaleString()} competitor push`, () => {
const queue = new CQueue<number>();
if (isCompetitor) {
suite.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`, () => {
for (let i = 0; i < LINEAR; i++) {
queue.push(i);
}
})
}
suite.add(`${LINEAR.toLocaleString()} push & shift`, () => {
const queue = new Queue<number>();
for (let i = 0; i < LINEAR; i++) {

View file

@ -2,6 +2,7 @@ import {Stack} from '../../../../src';
import {Stack as CStack} from 'js-sdsl';
import * as Benchmark from 'benchmark';
import {magnitude} from '../../../utils';
import {isCompetitor} from "../../../config";
const suite = new Benchmark.Suite();
const {LINEAR} = magnitude;
@ -14,24 +15,27 @@ suite
stack.push(i);
}
})
.add(`${LINEAR.toLocaleString()} competitor push`, () => {
if (isCompetitor) {
suite.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>();
}
suite.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`, () => {
for (let i = 0; i < LINEAR; i++) {
queue.push(i);
}
for (let i = 0; i < LINEAR; i++) {
queue.pop();
}
})
if (isCompetitor) {
suite.add(`${LINEAR.toLocaleString()} competitor push & pop`, () => {
const queue = new CStack<number>();
for (let i = 0; i < LINEAR; i++) {
@ -40,6 +44,7 @@ suite
for (let i = 0; i < LINEAR; i++) {
queue.pop();
}
});
})
}
export {suite};