Skip to content

Commit

Permalink
chore: Add performance regression test for TrackedArray
Browse files Browse the repository at this point in the history
- 100k items means that the performance test will take ~0.25s (1.7 GHz Quad-Core Intel Core i7) and seems be failing reliably.
- Added other assertions to make sure we're testing _real_ data and that we don't mutate the initial data set as we go.

Relates to: tracked-tools#405
  • Loading branch information
MichalBryxi committed Jan 26, 2024
1 parent de07bc4 commit c512944
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test-app/tests/unit/array-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ module('TrackedArray', function (hooks) {
assert.equal(arr[0], undefined);
});

test('Can perform well compared to native array', (assert) => {
const itemsCount = 100000;
const initialData = Array(itemsCount).fill(null);

const array1 = Array.from(initialData);
const t1 = performance.now();
array1.splice(0, 1);
const t2 = performance.now();
const controlWindow = t2 - t1;

const array2 = new TrackedArray(initialData);
const t3 = performance.now();
array2.splice(0, 1);
const t4 = performance.now();
const experimentWindow = t4 - t3;

const deviation = 1.2; // 20%
assert.ok(
experimentWindow < controlWindow * deviation,
`${experimentWindow} < ${controlWindow} * ${deviation}`,
);

assert.equal(initialData.length, itemsCount);
assert.equal(array1.length, itemsCount - 1);
assert.equal(array2.length, itemsCount - 1);
});

module('methods', () => {
test('isArray', (assert) => {
let arr = new TrackedArray();
Expand Down

0 comments on commit c512944

Please sign in to comment.