Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative performance tests #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/Signal/wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {describe, expect, it} from 'vitest';
import {Signal} from '../../src/wrapper.js';

describe('Performance', () => {
it('per-item unwatch is fast', () => {
const amountOfSignals = 10000;
const unwatchToWatchSlownessRatio = 35;
const w = new Signal.subtle.Watcher(() => {});
const signals = Array.from({length: amountOfSignals}, () => new Signal.State(1));
const watchStart = performance.now();
signals.forEach((s) => w.watch(s));
const watchEnd = performance.now();
const unwatchStart = performance.now();
signals.forEach((s) => w.unwatch(s));
const unwatchEnd = performance.now();
const watchTime = watchEnd - watchStart;
const unwatchTime = unwatchEnd - unwatchStart;

// we assume that unwatch can't be N times slower than watch
expect(unwatchTime).toBeLessThan(watchTime * unwatchToWatchSlownessRatio);

Check failure on line 20 in tests/Signal/wrapper.test.ts

View workflow job for this annotation

GitHub Actions / Test Firefox

tests/Signal/wrapper.test.ts > Performance > per-item unwatch is fast

AssertionError: expected 762 to be less than 210 ❯ AssertionError2 ../../../../../node_modules/.vite/deps/vitest___chai.js:38:17 ❯ methodWrapper ../../../../../node_modules/.vite/deps/vitest___chai.js:1044:29 ❯ tests/Signal/wrapper.test.ts:20:24
});
it('batch unwatch is fast', () => {
const amountOfSignals = 10000;
const unwatchToWatchSlownessRatio = 4;
const w = new Signal.subtle.Watcher(() => {});
const signals = Array.from({length: amountOfSignals}, () => new Signal.State(1));
const watchStart = performance.now();
signals.forEach((s) => w.watch(s));
const watchEnd = performance.now();
const unwatchStart = performance.now();
w.unwatch(...signals);
const unwatchEnd = performance.now();
const watchTime = watchEnd - watchStart;
const unwatchTime = unwatchEnd - unwatchStart;

expect(unwatchTime).toBeLessThan(watchTime * unwatchToWatchSlownessRatio);
});
});
Loading