Skip to content

Commit

Permalink
Added 1m entry random test (w/ timing)
Browse files Browse the repository at this point in the history
  • Loading branch information
n8allan committed Mar 30, 2024
1 parent 5ff29ee commit 36c9c5f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/b-tree.branching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ describe('Branching BTree', () => {
expect(tree.getCount()).toBe(0);
});

it('build a larger tree - randomly', () => {
const count = NodeCapacity * NodeCapacity * NodeCapacity * 4; // ~ 1 million
const randomStart = performance.now();
for (let i = 0; i !== count; ++i) {
Math.random();
}
const randomTime = performance.now() - randomStart;
const insertStart = performance.now();
for (let i = 0; i !== count; ++i) {
tree.insert(Math.random());
}
const insertTime = performance.now() - insertStart;
console.log(`Random: ${randomTime}ms, Insert: ${insertTime}ms, Net: ${insertTime - randomTime}ms`);
expect(tree.getCount()).toBeCloseTo(count, 2);
// Gut randomly
while (tree.first().on) {
const path = tree.find(Math.random());
if (!path.on) {
tree.moveNext(path);
}
if (!path.on) {
tree.movePrior(path);
}
tree.deleteAt(path);
}
expect(tree.getCount()).toBe(0);
});

it('getCount should give the correct number, whether ascending or descending, with a starting path, or not', () => {
const count = NodeCapacity * NodeCapacity + 1;
addRange(0, count);
Expand Down

0 comments on commit 36c9c5f

Please sign in to comment.