-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[binary-tree] Merge the operation of modifying the value into the ins…
…ert query process to improve performance. [benchmark] Enhance performance test cases and move existing performance tests from unit tests to the 'performance' section. Improve the benchmark test report. Refine the logic of the report generator.
- Loading branch information
Showing
41 changed files
with
346 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {AVLTree} from '../../../../src'; | ||
import * as Benchmark from 'benchmark'; | ||
import {magnitude, randomInt, randomIntArray} from '../../../utils'; | ||
|
||
const suite = new Benchmark.Suite(); | ||
const avl = new AVLTree<number>(); | ||
const {N_LOG_N} = magnitude; | ||
|
||
suite | ||
.add(`add ${N_LOG_N} randomly`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) avl.add(randomInt(0, N_LOG_N)); | ||
}) | ||
.add(`delete ${N_LOG_N} randomly`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) avl.delete(randomInt(0, N_LOG_N)); | ||
}) | ||
.add(`addMany ${N_LOG_N}`, () => { | ||
const arr = randomIntArray(N_LOG_N); | ||
avl.addMany(arr); | ||
}) | ||
.add(`get ${N_LOG_N}`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) avl.get(randomInt(-N_LOG_N, N_LOG_N)); | ||
}); | ||
|
||
export {suite}; |
29 changes: 18 additions & 11 deletions
29
test/performance/data-structures/binary-tree/binary-tree.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import {BinaryTree} from '../../../../src'; | ||
|
||
import * as Benchmark from 'benchmark'; | ||
import {magnitude, randomInt, randomIntArray} from '../../../utils'; | ||
|
||
export const suite = new Benchmark.Suite(); | ||
const bt = new BinaryTree<number>(); | ||
const suite = new Benchmark.Suite(); | ||
const biTree = new BinaryTree<number>(); | ||
const {N_LOG_N} = magnitude; | ||
|
||
suite | ||
.add('add 1000', () => { | ||
for (let i = 0; i < 1000; i++) { | ||
bt.add(i); | ||
} | ||
.add(`add ${N_LOG_N}`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) biTree.add(randomInt(-N_LOG_N, N_LOG_N)); | ||
}) | ||
.add(`delete ${N_LOG_N}`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) biTree.delete(randomInt(-N_LOG_N, N_LOG_N)); | ||
}) | ||
.add('add & delete 1000', () => { | ||
for (let i = 0; i < 1000; i++) { | ||
bt.delete(i); | ||
} | ||
.add(`addMany ${N_LOG_N}`, () => { | ||
biTree.clear(); | ||
const arr = randomIntArray(N_LOG_N); | ||
biTree.addMany(arr); | ||
}) | ||
.add(`get ${N_LOG_N}`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) biTree.get(randomInt(-N_LOG_N, N_LOG_N)); | ||
}); | ||
|
||
export {suite}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import {BST} from '../../../../src'; | ||
|
||
import * as Benchmark from 'benchmark'; | ||
import {magnitude, randomInt, randomIntArray} from '../../../utils'; | ||
|
||
export const suite = new Benchmark.Suite(); | ||
const bt = new BST<number>(); | ||
const suite = new Benchmark.Suite(); | ||
const bst = new BST<number>(); | ||
const {N_LOG_N} = magnitude; | ||
|
||
suite | ||
.add('add 1000', () => { | ||
for (let i = 0; i < 1000; i++) { | ||
bt.add(i); | ||
} | ||
.add(`add ${N_LOG_N} randomly`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) bst.add(randomInt(0, N_LOG_N)); | ||
}) | ||
.add(`delete ${N_LOG_N} randomly`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) bst.delete(randomInt(0, N_LOG_N)); | ||
}) | ||
.add('add & delete 1000', () => { | ||
for (let i = 0; i < 1000; i++) { | ||
bt.delete(i); | ||
} | ||
.add(`addMany ${N_LOG_N} balanced`, () => { | ||
const arr = randomIntArray(N_LOG_N); | ||
bst.addMany(arr); | ||
}) | ||
.add(`get ${N_LOG_N}`, () => { | ||
for (let i = 0; i < N_LOG_N; i++) bst.get(randomInt(-N_LOG_N, N_LOG_N)); | ||
}); | ||
|
||
export {suite}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {FibonacciHeap, Heap} from '../../../../src'; | ||
import * as Benchmark from 'benchmark'; | ||
import {magnitude} from '../../../utils'; | ||
|
||
const suite = new Benchmark.Suite(); | ||
const {N_LOG_N} = magnitude; | ||
|
||
suite | ||
.add(`add & ${N_LOG_N}`, () => { | ||
const heap = new Heap<number>({comparator: (a, b) => b - a}); | ||
|
||
for (let i = 0; i < N_LOG_N; i++) { | ||
heap.add(i); | ||
} | ||
|
||
for (let i = 0; i < N_LOG_N; i++) { | ||
heap.pop(); | ||
} | ||
}) | ||
.add(`fib add & pop ${N_LOG_N}`, () => { | ||
const fbHeap = new FibonacciHeap<number>(); | ||
for (let i = 1; i <= N_LOG_N; i++) { | ||
fbHeap.push(i); | ||
} | ||
for (let i = 1; i <= N_LOG_N; i++) { | ||
fbHeap.pop(); | ||
} | ||
}); | ||
|
||
export {suite}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src'; | ||
import * as Benchmark from 'benchmark'; | ||
import {magnitude} from '../../../utils'; | ||
|
||
const suite = new Benchmark.Suite(); | ||
const {LINEAR, N_LOG_N} = magnitude; | ||
|
||
suite | ||
.add(`unshift ${LINEAR}`, () => { | ||
const list = new DoublyLinkedList<number>(); | ||
|
||
for (let i = 0; i < LINEAR; i++) { | ||
list.unshift(i); | ||
} | ||
}) | ||
.add(`unshift & shift ${LINEAR}`, () => { | ||
const list = new DoublyLinkedList<number>(); | ||
|
||
for (let i = 0; i < LINEAR; i++) { | ||
list.unshift(i); | ||
} | ||
for (let i = 0; i < LINEAR; i++) { | ||
list.shift(); | ||
} | ||
}) | ||
.add(`insertBefore ${N_LOG_N}`, () => { | ||
const doublyList = new DoublyLinkedList<number>(); | ||
let midNode: DoublyLinkedListNode | null = null; | ||
const midIndex = Math.floor(N_LOG_N / 2); | ||
for (let i = 0; i < N_LOG_N; i++) { | ||
doublyList.push(i); | ||
if (i === midIndex) { | ||
midNode = doublyList.getNode(i); | ||
} else if (i > midIndex && midNode) { | ||
doublyList.insertBefore(midNode, i); | ||
} | ||
} | ||
}); | ||
|
||
export {suite}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {SinglyLinkedList, SinglyLinkedListNode} from '../../../../src'; | ||
import * as Benchmark from 'benchmark'; | ||
import {magnitude} from '../../../utils'; | ||
|
||
const suite = new Benchmark.Suite(); | ||
const {N_LOG_N} = magnitude; | ||
|
||
suite | ||
.add(`push & pop ${N_LOG_N}`, () => { | ||
const list = new SinglyLinkedList<number>(); | ||
|
||
for (let i = 0; i < N_LOG_N; i++) { | ||
list.push(i); | ||
} | ||
|
||
for (let i = 0; i < N_LOG_N; i++) { | ||
list.pop(); | ||
} | ||
}) | ||
.add(`insertBefore ${N_LOG_N}`, () => { | ||
const singlyList = new SinglyLinkedList<number>(); | ||
let midSinglyNode: SinglyLinkedListNode | null = null; | ||
const midIndex = Math.floor(N_LOG_N / 2); | ||
for (let i = 0; i < N_LOG_N; i++) { | ||
singlyList.push(i); | ||
if (i === midIndex) { | ||
midSinglyNode = singlyList.getNode(i); | ||
} else if (i > midIndex && midSinglyNode) { | ||
singlyList.insertBefore(midSinglyNode.value, i); | ||
} | ||
} | ||
}); | ||
|
||
export {suite}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {MaxPriorityQueue} from '../../../../src'; | ||
import * as Benchmark from 'benchmark'; | ||
import {magnitude} from '../../../utils'; | ||
|
||
const suite = new Benchmark.Suite(); | ||
const {LINEAR} = magnitude; | ||
|
||
suite.add(`refill & poll ${LINEAR}`, () => { | ||
const nodes = Array.from( | ||
new Set<number>(Array.from(new Array(LINEAR), () => Math.floor(Math.random() * LINEAR * 100))) | ||
); | ||
const maxPQ = new MaxPriorityQueue<number>(); | ||
maxPQ.refill(nodes); | ||
while (maxPQ.size > 0) { | ||
maxPQ.poll(); | ||
} | ||
}); | ||
|
||
export {suite}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import {Queue} from '../../../../src'; | ||
|
||
import * as Benchmark from 'benchmark'; | ||
import {magnitude} from '../../../utils'; | ||
|
||
export const suite = new Benchmark.Suite(); | ||
const suite = new Benchmark.Suite(); | ||
const {LINEAR} = magnitude; | ||
|
||
suite | ||
.add('push 1000000', () => { | ||
.add(`push ${LINEAR}`, () => { | ||
const queue = new Queue<number>(); | ||
for (let i = 0; i < 1000000; i++) { | ||
|
||
for (let i = 0; i < LINEAR; i++) { | ||
queue.push(i); | ||
} | ||
}) | ||
.add('push & shift 1000000', () => { | ||
.add(`push & shift ${LINEAR}`, () => { | ||
const queue = new Queue<number>(); | ||
for (let i = 0; i < 1000000; i++) { | ||
|
||
for (let i = 0; i < LINEAR; i++) { | ||
queue.push(i); | ||
queue.shift(); | ||
} | ||
}); | ||
|
||
export {suite}; |
Oops, something went wrong.