-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_benchmark.ts
More file actions
60 lines (53 loc) · 1.3 KB
/
_benchmark.ts
File metadata and controls
60 lines (53 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { decodePNG, encodePNG } from "@img/png";
import { decodeQOI, encodeQOI } from "@img/qoi";
const width = 256;
const height = 256;
function getData(): Promise<Uint8Array<ArrayBuffer>> {
return new Response(
ReadableStream.from(function* (): Generator<Uint8Array<ArrayBuffer>> {
for (let r = 0; r < width; ++r) {
for (let c = 0; c < height; ++c) {
yield Uint8Array.from([255 - r, c, r, 255]);
}
}
}()),
)
.bytes() as Promise<Uint8Array<ArrayBuffer>>;
}
const RAW_INPUT = await getData();
const QOI_ENCODED = encodeQOI(RAW_INPUT.slice(), {
width,
height,
channels: "rgba",
colorspace: 0,
});
const PNG_ENCODED = await encodePNG(RAW_INPUT.slice(), {
width,
height,
compression: 0,
filter: 0,
interlace: 0,
});
Deno.bench({ name: "QOI", group: "encode" }, () => {
encodeQOI(RAW_INPUT.slice(), {
width,
height,
channels: "rgba",
colorspace: 0,
});
});
Deno.bench({ name: "PNG", group: "encode" }, async () => {
await encodePNG(RAW_INPUT.slice(), {
width,
height,
compression: 0,
filter: 0,
interlace: 0,
});
});
Deno.bench({ name: "QOI", group: "decode" }, () => {
decodeQOI(QOI_ENCODED.slice());
});
Deno.bench({ name: "PNG", group: "decode" }, async () => {
await decodePNG(PNG_ENCODED.slice());
});