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

Add measure of roundtrip performance for ArrayBuffers in coverall2 test #99

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
37 changes: 36 additions & 1 deletion fixtures/coverall2/tests/bindings/test_coverall2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@ test("array buffer roundtrip using read/write", (t) => {
}
});

test("ArrayBuffer roundtrip of different sizes", (t) => {
function rt(ab: ArrayBuffer) {
t.assertNotNull(identityArrayBuffer(ab)!);
}
// 1 kB = 1<<10
// 1 MB = 1<<20
// 16 MB = 1<<24
for (let i = 0; i < 26; i++) {
const byteLength = 1 << i;
const buffer = new ArrayBuffer(byteLength);
const start = Date.now();
rt(buffer);
const end = Date.now();
console.log(
`ArrayBuffer roundtrip: ${bytes(byteLength)} in ${end - start} ms`,
);
}
});

function bytes(n: number): string {
if (n === 0) {
return "0 bytes";
}
if (n < 1 << 10) {
return `${n} bytes`;
}
if (n < 1 << 20) {
return `${n / (1 << 10)} kB`;
}
if (n < 1 << 30) {
return `${n / (1 << 20)} MB`;
}
return `${n / (1 << 30)} GB`;
}

test("array buffer roundtrip with ArrayBufferView", (t) => {
function rt(ab: ArrayBuffer) {
t.assertEqual(
Expand Down Expand Up @@ -107,6 +142,6 @@ function abEquals(a: ArrayBuffer, b: ArrayBuffer): boolean {
}

function arrayBuffer(numBytes: number): ArrayBuffer {
const array = Uint8Array.from({ length: numBytes }, (_v, i) => i);
const array = Uint8Array.from({ length: numBytes }, (_v, i) => i % 255);
return array.buffer;
}