Skip to content
Closed
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
32 changes: 17 additions & 15 deletions packages/big-endian/bench/decode.bench.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import { bench, describe } from "vitest"
import decode from "../src/index.js"
import { bench, describe } from "vitest";
import decode from "../src/index.js";

const SIZE_512x512 = 512 * 512
const SIZE_512x512 = 512 * 512;

// REMOVE THIS COMMENT. IT IS JUST BEING ADDED SO THE BENCH CAN RUN.

function makeBuffer(byteLen) {
const data = new Uint8Array(byteLen)
for (let i = 0; i < byteLen; i++) data[i] = (i * 37) & 0xff
return data
const data = new Uint8Array(byteLen);
for (let i = 0; i < byteLen; i++) data[i] = (i * 37) & 0xff;
return data;
}

describe("big-endian decode (byte-swap)", () => {
const data16 = makeBuffer(SIZE_512x512 * 2)
const data16 = makeBuffer(SIZE_512x512 * 2);

bench("16-bit unsigned + swap, 512x512", () => {
decode({ bitsAllocated: 16, pixelRepresentation: 0 }, data16)
})
decode({ bitsAllocated: 16, pixelRepresentation: 0 }, data16);
});

bench("16-bit signed + swap, 512x512", () => {
decode({ bitsAllocated: 16, pixelRepresentation: 1 }, data16)
})
decode({ bitsAllocated: 16, pixelRepresentation: 1 }, data16);
});

// The 16-bit benches above do real per-pixel swap work and are left
// unbatched. The 8-bit path is a bare property assignment, so a single
// call is swamped by fixed harness overhead and cache-model variation
// across runner CPUs; batch x100 so the body is measurable.
const data8 = makeBuffer(SIZE_512x512)
const data8 = makeBuffer(SIZE_512x512);
bench("8-bit passthrough, 512x512 x100", () => {
for (let i = 0; i < 100; i++) {
decode({ bitsAllocated: 8 }, data8)
decode({ bitsAllocated: 8 }, data8);
}
})
})
});
});
Loading