mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
refactor: Constrain the getter size() from the base class. Refactor some inappropriate performance tests.
feat: Add sorting capability to performance test reports.
This commit is contained in:
parent
4747839d88
commit
f8832a04c0
71
README.md
71
README.md
|
@ -989,46 +989,55 @@ concurrently.
|
|||
|
||||
## Benchmark
|
||||
|
||||
macOS Big Sur
|
||||
Version 11.7.9
|
||||
|
||||
MacBook Pro (15-inch, 2018)
|
||||
Processor 2.2 GHz 6-Core Intel Core i7
|
||||
Memory 16 GB 2400 MHz DDR4
|
||||
Graphics Radeon Pro 555X 4 GB
|
||||
Intel UHD Graphics 630 1536 MB
|
||||
|
||||
[//]: # (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>125.60</td><td>7.96</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>181.22</td><td>5.52</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>134.12</td><td>7.46</td><td>0.01</td></tr><tr><td>10,000 get</td><td>55.08</td><td>18.16</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'>binary-tree-overall</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 RBTree add</td><td>6.17</td><td>161.95</td><td>0.00</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>16.07</td><td>62.22</td><td>2.62e-4</td></tr><tr><td>10,000 RBTree get</td><td>19.86</td><td>50.36</td><td>2.44e-4</td></tr><tr><td>10,000 AVLTree add</td><td>134.38</td><td>7.44</td><td>0.02</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>207.20</td><td>4.83</td><td>0.06</td></tr><tr><td>10,000 AVLTree get</td><td>0.98</td><td>1015.54</td><td>2.73e-5</td></tr></table></div>
|
||||
<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>100,000 add</td><td>6.51</td><td>153.59</td><td>4.60e-4</td></tr><tr><td>100,000 add & poll</td><td>31.59</td><td>31.65</td><td>8.52e-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</td><td>86.65</td><td>11.54</td><td>0.02</td></tr><tr><td>100,000 add & delete randomly</td><td>221.02</td><td>4.52</td><td>0.03</td></tr><tr><td>100,000 getNode</td><td>190.54</td><td>5.25</td><td>0.00</td></tr><tr><td>100,000 add & iterator</td><td>122.10</td><td>8.19</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'>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>8896.51</td><td>2.63e-5</td></tr><tr><td>1,000 addEdge</td><td>6.53</td><td>153.21</td><td>0.00</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.08e+4</td><td>1.06e-5</td></tr><tr><td>1,000 getEdge</td><td>27.53</td><td>36.33</td><td>0.01</td></tr><tr><td>tarjan</td><td>224.53</td><td>4.45</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>184.02</td><td>5.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'>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>1,000,000 set</td><td>126.27</td><td>7.92</td><td>0.05</td></tr><tr><td>Native Map 1,000,000 set</td><td>229.80</td><td>4.35</td><td>0.03</td></tr><tr><td>Native Set 1,000,000 add</td><td>175.83</td><td>5.69</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>121.34</td><td>8.24</td><td>0.03</td></tr><tr><td>Native Map 1,000,000 set & get</td><td>290.80</td><td>3.44</td><td>0.03</td></tr><tr><td>Native Set 1,000,000 add & has</td><td>180.71</td><td>5.53</td><td>0.01</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>357.68</td><td>2.80</td><td>0.07</td></tr><tr><td>Native Map 1,000,000 ObjKey set & get</td><td>310.57</td><td>3.22</td><td>0.06</td></tr><tr><td>Native Set 1,000,000 ObjKey add & has</td><td>278.42</td><td>3.59</td><td>0.05</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>100,000 add & poll</td><td>24.85</td><td>40.24</td><td>0.00</td></tr><tr><td>100,000 add & dfs</td><td>33.14</td><td>30.17</td><td>0.00</td></tr><tr><td>10,000 fib add & pop</td><td>366.11</td><td>2.73</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 push</td><td>217.98</td><td>4.59</td><td>0.07</td></tr><tr><td>1,000,000 unshift</td><td>223.20</td><td>4.48</td><td>0.08</td></tr><tr><td>1,000,000 unshift & shift</td><td>172.87</td><td>5.78</td><td>0.03</td></tr><tr><td>1,000,000 addBefore</td><td>387.13</td><td>2.58</td><td>0.20</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>1,000,000 push & shift</td><td>225.13</td><td>4.44</td><td>0.07</td></tr><tr><td>10,000 push & pop</td><td>234.54</td><td>4.26</td><td>0.02</td></tr><tr><td>10,000 addBefore</td><td>252.62</td><td>3.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'>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>100,000 add & poll</td><td>76.49</td><td>13.07</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'>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>13.20</td><td>75.75</td><td>2.79e-4</td></tr><tr><td>1,000,000 push & pop</td><td>22.21</td><td>45.03</td><td>3.27e-4</td></tr><tr><td>100,000 push & shift</td><td>2.26</td><td>442.24</td><td>1.43e-4</td></tr><tr><td>Native Array 100,000 push & shift</td><td>2329.51</td><td>0.43</td><td>0.10</td></tr><tr><td>100,000 unshift & shift</td><td>2.16</td><td>463.83</td><td>8.20e-5</td></tr><tr><td>Native Array 100,000 unshift & shift</td><td>4590.64</td><td>0.22</td><td>0.33</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</td><td>85.08</td><td>11.75</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>217.11</td><td>4.61</td><td>0.02</td></tr><tr><td>100,000 getNode</td><td>178.00</td><td>5.62</td><td>0.00</td></tr><tr><td>100,000 add & iterator</td><td>116.31</td><td>8.60</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>49.92</td><td>20.03</td><td>0.02</td></tr><tr><td>100,000 push & shift</td><td>5.07</td><td>197.28</td><td>5.86e-4</td></tr><tr><td>Native Array 100,000 push & shift</td><td>2315.78</td><td>0.43</td><td>0.13</td></tr><tr><td>Native Array 100,000 push & pop</td><td>4.37</td><td>228.72</td><td>1.32e-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>1,000,000 push</td><td>45.98</td><td>21.75</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>4.91</td><td>203.49</td><td>7.39e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2321.55</td><td>0.43</td><td>0.20</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.50</td><td>22.47</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>53.57</td><td>18.67</td><td>0.02</td></tr></table></div>
|
||||
<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>24.85</td><td>40.24</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>31.50</td><td>31.75</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>30.93</td><td>32.33</td><td>0.00</td></tr><tr><td>100,000 push & shift</td><td>3.28</td><td>304.69</td><td>2.35e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2040.48</td><td>0.49</td><td>0.08</td></tr><tr><td>100,000 unshift & shift</td><td>2.97</td><td>336.20</td><td>5.34e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4113.19</td><td>0.24</td><td>0.25</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>1,000,000 set</td><td>118.59</td><td>8.43</td><td>0.03</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>208.83</td><td>4.79</td><td>0.02</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>168.45</td><td>5.94</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>120.86</td><td>8.27</td><td>0.02</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>270.83</td><td>3.69</td><td>0.02</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>168.79</td><td>5.92</td><td>0.01</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>335.67</td><td>2.98</td><td>0.05</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>302.02</td><td>3.31</td><td>0.04</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>270.81</td><td>3.69</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'>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>42.95</td><td>23.28</td><td>6.68e-4</td></tr><tr><td>100,000 getWords</td><td>92.11</td><td>10.86</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.86</td><td>22.29</td><td>9.69e-4</td></tr><tr><td>100,000 getWords</td><td>85.63</td><td>11.68</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'>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>128.11</td><td>7.81</td><td>0.00</td></tr><tr><td>10,000 get</td><td>52.87</td><td>18.91</td><td>6.02e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>189.76</td><td>5.27</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>136.54</td><td>7.32</td><td>9.74e-4</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-overall</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 RBTree add</td><td>7.00</td><td>142.81</td><td>9.38e-5</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>16.85</td><td>59.34</td><td>1.65e-4</td></tr><tr><td>10,000 RBTree get</td><td>18.20</td><td>54.93</td><td>1.45e-4</td></tr><tr><td>10,000 AVLTree add</td><td>127.56</td><td>7.84</td><td>0.00</td></tr><tr><td>10,000 AVLTree get</td><td>53.38</td><td>18.73</td><td>7.89e-4</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>190.11</td><td>5.26</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>9828.43</td><td>2.34e-6</td></tr><tr><td>1,000 addEdge</td><td>6.14</td><td>162.81</td><td>1.71e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>4.30e-7</td></tr><tr><td>1,000 getEdge</td><td>23.02</td><td>43.44</td><td>0.00</td></tr><tr><td>tarjan</td><td>202.41</td><td>4.94</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>180.32</td><td>5.55</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 push</td><td>209.36</td><td>4.78</td><td>0.04</td></tr><tr><td>1,000,000 unshift</td><td>217.02</td><td>4.61</td><td>0.08</td></tr><tr><td>1,000,000 unshift & shift</td><td>174.28</td><td>5.74</td><td>0.05</td></tr><tr><td>1,000,000 addBefore</td><td>331.23</td><td>3.02</td><td>0.08</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>1,000,000 push & shift</td><td>217.34</td><td>4.60</td><td>0.07</td></tr><tr><td>10,000 push & pop</td><td>216.54</td><td>4.62</td><td>0.01</td></tr><tr><td>10,000 addBefore</td><td>247.69</td><td>4.04</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'>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>100,000 add</td><td>27.82</td><td>35.94</td><td>0.00</td></tr><tr><td>100,000 add & poll</td><td>78.76</td><td>12.70</td><td>0.02</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>40.75</td><td>24.54</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>48.07</td><td>20.80</td><td>0.01</td></tr></table></div>
|
||||
</div>
|
||||
|
||||
[//]: # (No deletion!!! End of Replace Section)
|
||||
|
|
|
@ -6,6 +6,8 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|||
* Space Complexity: O(1)
|
||||
*/
|
||||
|
||||
abstract get size(): number;
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
|
@ -125,6 +127,11 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
|
@ -248,11 +255,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
|
@ -301,6 +303,8 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|||
}
|
||||
|
||||
export abstract class IterableElementBase<E = any, C = any> {
|
||||
abstract get size(): number;
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
|
@ -362,6 +366,11 @@ export abstract class IterableElementBase<E = any, C = any> {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
|
@ -445,11 +454,6 @@ export abstract class IterableElementBase<E = any, C = any> {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Time Complexity: O(n)
|
||||
* Space Complexity: O(1)
|
||||
|
|
|
@ -82,6 +82,10 @@ export abstract class AbstractGraph<
|
|||
this._vertexMap = v;
|
||||
}
|
||||
|
||||
get size(): number {
|
||||
return this._vertexMap.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
||||
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
||||
|
|
|
@ -200,7 +200,7 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|||
* @param element - the element to check.
|
||||
* @returns Returns true if the specified element is contained; otherwise, returns false.
|
||||
*/
|
||||
has(element: E): boolean {
|
||||
override has(element: E): boolean {
|
||||
return this.elements.includes(element);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@ suite
|
|||
avl.clear();
|
||||
for (let i = 0; i < arr.length; i++) avl.add(arr[i]);
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} get`, () => {
|
||||
for (let i = 0; i < arr.length; i++) avl.get(arr[i]);
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} add & delete randomly`, () => {
|
||||
avl.clear();
|
||||
for (let i = 0; i < arr.length; i++) avl.add(arr[i]);
|
||||
|
@ -20,9 +23,6 @@ suite
|
|||
.add(`${TEN_THOUSAND.toLocaleString()} addMany`, () => {
|
||||
avl.clear();
|
||||
avl.addMany(arr);
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} get`, () => {
|
||||
for (let i = 0; i < arr.length; i++) avl.get(arr[i]);
|
||||
});
|
||||
|
||||
export { suite };
|
||||
|
|
|
@ -25,13 +25,13 @@ suite
|
|||
avlTree.clear();
|
||||
for (let i = 0; i < arr.length; i++) avlTree.add(arr[i]);
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} AVLTree get`, () => {
|
||||
for (let i = 0; i < arr.length; i++) avlTree.get(arr[i]);
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} AVLTree add & delete randomly`, () => {
|
||||
avlTree.clear();
|
||||
for (let i = 0; i < arr.length; i++) avlTree.add(arr[i]);
|
||||
for (let i = 0; i < arr.length; i++) avlTree.delete(arr[i]);
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} AVLTree get`, () => {
|
||||
for (let i = 0; i < arr.length; i++) avlTree.get(arr[i]);
|
||||
});
|
||||
|
||||
export { suite };
|
||||
|
|
|
@ -21,13 +21,13 @@ if (isCompetitor) {
|
|||
});
|
||||
}
|
||||
|
||||
suite.add(`Native Map ${MILLION.toLocaleString()} set`, () => {
|
||||
suite.add(`Native JS Map ${MILLION.toLocaleString()} set`, () => {
|
||||
const hm = new Map<number, number>();
|
||||
|
||||
for (let i = 0; i < MILLION; i++) hm.set(i, i);
|
||||
});
|
||||
|
||||
suite.add(`Native Set ${MILLION.toLocaleString()} add`, () => {
|
||||
suite.add(`Native JS Set ${MILLION.toLocaleString()} add`, () => {
|
||||
const hs = new Set<number>();
|
||||
|
||||
for (let i = 0; i < MILLION; i++) hs.add(i);
|
||||
|
@ -49,14 +49,14 @@ if (isCompetitor) {
|
|||
});
|
||||
}
|
||||
|
||||
suite.add(`Native Map ${MILLION.toLocaleString()} set & get`, () => {
|
||||
suite.add(`Native JS Map ${MILLION.toLocaleString()} set & get`, () => {
|
||||
const hm = new Map<number, number>();
|
||||
|
||||
for (let i = 0; i < MILLION; i++) hm.set(i, i);
|
||||
for (let i = 0; i < MILLION; i++) hm.get(i);
|
||||
});
|
||||
|
||||
suite.add(`Native Set ${MILLION.toLocaleString()} add & has`, () => {
|
||||
suite.add(`Native JS Set ${MILLION.toLocaleString()} add & has`, () => {
|
||||
const hs = new Set<number>();
|
||||
|
||||
for (let i = 0; i < MILLION; i++) hs.add(i);
|
||||
|
@ -74,7 +74,7 @@ suite.add(`${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|||
for (let i = 0; i < MILLION; i++) hm.get(objKeys[i]);
|
||||
});
|
||||
|
||||
suite.add(`Native Map ${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
||||
suite.add(`Native JS Map ${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
||||
const hm = new Map<[number, number], number>();
|
||||
const objs: [number, number][] = [];
|
||||
for (let i = 0; i < MILLION; i++) {
|
||||
|
@ -85,7 +85,7 @@ suite.add(`Native Map ${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|||
for (let i = 0; i < MILLION; i++) hm.get(objs[i]);
|
||||
});
|
||||
|
||||
suite.add(`Native Set ${MILLION.toLocaleString()} ObjKey add & has`, () => {
|
||||
suite.add(`Native JS Set ${MILLION.toLocaleString()} ObjKey add & has`, () => {
|
||||
const hs = new Set<[number, number]>();
|
||||
const objs: [number, number][] = [];
|
||||
for (let i = 0; i < MILLION; i++) {
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
import { FibonacciHeap, Heap } from '../../../../src';
|
||||
import { Heap } from '../../../../src';
|
||||
import * as Benchmark from 'benchmark';
|
||||
import { magnitude } from '../../../utils';
|
||||
import { getRandomInt, magnitude } from '../../../utils';
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
const { HUNDRED_THOUSAND, TEN_THOUSAND } = magnitude;
|
||||
const { HUNDRED_THOUSAND } = magnitude;
|
||||
const indicesHT = new Array(HUNDRED_THOUSAND).fill(0).map(() => getRandomInt(0, HUNDRED_THOUSAND - 1));
|
||||
|
||||
suite
|
||||
.add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
|
||||
const heap = new Heap<number>([], { comparator: (a, b) => b - a });
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(indicesHT[i]);
|
||||
})
|
||||
.add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
|
||||
const heap = new Heap<number>([], { comparator: (a, b) => b - a });
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(indicesHT[i]);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.poll();
|
||||
})
|
||||
.add(`${HUNDRED_THOUSAND.toLocaleString()} add & dfs`, () => {
|
||||
const heap = new Heap<number>([], { comparator: (a, b) => b - a });
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
|
||||
heap.dfs();
|
||||
})
|
||||
.add(`${TEN_THOUSAND.toLocaleString()} fib add & pop`, () => {
|
||||
const fbHeap = new FibonacciHeap<number>();
|
||||
for (let i = 1; i <= TEN_THOUSAND; i++) fbHeap.push(i);
|
||||
for (let i = 1; i <= TEN_THOUSAND; i++) fbHeap.pop();
|
||||
});
|
||||
// .add(`${TEN_THOUSAND.toLocaleString()} fib add & pop`, () => {
|
||||
// const fbHeap = new FibonacciHeap<number>();
|
||||
// for (let i = 1; i <= TEN_THOUSAND; i++) fbHeap.push(i);
|
||||
// for (let i = 1; i <= TEN_THOUSAND; i++) fbHeap.pop();
|
||||
// });
|
||||
|
||||
export { suite };
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { PriorityQueue as CPriorityQueue } from 'js-sdsl';
|
||||
import { PriorityQueue } from '../../../../src';
|
||||
import { PriorityQueue as CPriorityQueue } from 'js-sdsl';
|
||||
import * as Benchmark from 'benchmark';
|
||||
import { magnitude } from '../../../utils';
|
||||
import { isCompetitor } from '../../../config';
|
||||
|
@ -7,12 +7,17 @@ import { isCompetitor } from '../../../config';
|
|||
const suite = new Benchmark.Suite();
|
||||
const { HUNDRED_THOUSAND } = magnitude;
|
||||
|
||||
suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
|
||||
const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
|
||||
suite
|
||||
.add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
|
||||
const heap = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
|
||||
})
|
||||
.add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
|
||||
const heap = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) pq.add(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) pq.poll();
|
||||
});
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.poll();
|
||||
});
|
||||
if (isCompetitor) {
|
||||
suite.add(`CPT ${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
|
||||
const pq = new CPriorityQueue<number>();
|
||||
|
|
|
@ -21,25 +21,25 @@ if (isCompetitor) {
|
|||
}
|
||||
|
||||
suite
|
||||
// .add(`${TEN_THOUSAND.toLocaleString()} push & delete`, () => {
|
||||
// const deque = new Deque<number>();
|
||||
//
|
||||
// for (let i = 0; i < TEN_THOUSAND; i++) deque.push(i);
|
||||
// for (let i = 0; i < TEN_THOUSAND; i++) deque.delete(randomIndicesTenThousand[i]);
|
||||
// })
|
||||
.add(`${MILLION.toLocaleString()} push & pop`, () => {
|
||||
const deque = new Deque<number>();
|
||||
|
||||
for (let i = 0; i < MILLION; i++) deque.push(i);
|
||||
for (let i = 0; i < MILLION; i++) deque.pop();
|
||||
})
|
||||
.add(`${MILLION.toLocaleString()} push & shift`, () => {
|
||||
const deque = new Deque<number>();
|
||||
|
||||
for (let i = 0; i < MILLION; i++) deque.push(i);
|
||||
for (let i = 0; i < MILLION; i++) deque.shift();
|
||||
})
|
||||
.add(`${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
||||
const deque = new Deque<number>();
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) deque.push(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) deque.shift();
|
||||
})
|
||||
.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
||||
.add(`Native JS Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
||||
const array = new Array<number>();
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) array.push(i);
|
||||
|
@ -51,7 +51,7 @@ suite
|
|||
for (let i = 0; i < HUNDRED_THOUSAND; i++) deque.unshift(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) deque.shift();
|
||||
})
|
||||
.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} unshift & shift`, () => {
|
||||
.add(`Native JS Array ${HUNDRED_THOUSAND.toLocaleString()} unshift & shift`, () => {
|
||||
const array = new Array<number>();
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) array.unshift(i);
|
||||
|
|
|
@ -25,18 +25,11 @@ suite.add(`${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
|||
for (let i = 0; i < HUNDRED_THOUSAND; i++) queue.push(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) queue.shift();
|
||||
});
|
||||
suite
|
||||
.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
||||
const arr = new Array<number>();
|
||||
suite.add(`Native JS Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
||||
const arr = new Array<number>();
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.push(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.shift();
|
||||
})
|
||||
.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & pop`, () => {
|
||||
const arr = new Array<number>();
|
||||
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.push(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.pop();
|
||||
});
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.push(i);
|
||||
for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.shift();
|
||||
});
|
||||
|
||||
export { suite };
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as fs from 'fs';
|
|||
import * as fastGlob from 'fast-glob';
|
||||
import { Color, numberFix, render } from '../utils';
|
||||
import { PerformanceTest } from './types';
|
||||
import * as console from 'console';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
|
@ -171,7 +172,48 @@ function replaceMarkdownContent(startMarker: string, endMarker: string, newText:
|
|||
});
|
||||
}
|
||||
|
||||
performanceTests.forEach(item => {
|
||||
const order = [
|
||||
'heap',
|
||||
'rb-tree',
|
||||
'queue',
|
||||
'deque',
|
||||
'hash-map',
|
||||
'trie',
|
||||
'avl-tree',
|
||||
'binary-tree-overall',
|
||||
'directed-graph',
|
||||
'doubly-linked-list',
|
||||
'singly-linked-list',
|
||||
'priority-queue',
|
||||
'stack'
|
||||
];
|
||||
|
||||
const sortedPerformanceTests = [...performanceTests].sort((a, b) => {
|
||||
const indexA = order.indexOf(a.testName);
|
||||
const indexB = order.indexOf(b.testName);
|
||||
|
||||
// If both a and b are in the order, sort them according to their indices in the order.
|
||||
if (indexA !== -1 && indexB !== -1) {
|
||||
return indexA - indexB;
|
||||
}
|
||||
|
||||
// If there is only 'a' in the order, then place 'b' in front.
|
||||
if (indexA !== -1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If only b is in the order, then a should be placed before it.
|
||||
if (indexB !== -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If neither a nor b are in order, keep their original order
|
||||
return 0;
|
||||
});
|
||||
|
||||
console.log(`${GREEN} Found tests${END}: ${sortedPerformanceTests.map(test => test.testName)}`);
|
||||
|
||||
sortedPerformanceTests.forEach(item => {
|
||||
const { suite, testName, file } = item;
|
||||
|
||||
console.log(coloredLabeled('Running', file));
|
||||
|
|
Loading…
Reference in a new issue