-
Notifications
You must be signed in to change notification settings - Fork 7
/
bench-node.js
51 lines (43 loc) · 1001 Bytes
/
bench-node.js
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
import {
convert,
OKLCH,
sRGB,
sRGBGamut,
listColorSpaces,
gamutMapOKLCH,
} from "../src/index.js";
const spaces = listColorSpaces().filter((f) => !/ok(hsv|hsl)/i.test(f.id));
const vecs = Array(128 * 128)
.fill()
.map((_, i, lst) => {
const t = i / (lst.length - 1);
return (
Array(3)
.fill()
// -0.5 .. 1.5
.map(() => t + (t * 2 - 1) * 0.5)
);
});
const tmp = [0, 0, 0];
// console.time("bench");
for (let vec of vecs) {
for (let i = 0; i < spaces.length; i++) {
for (let j = 0; j < spaces.length; j++) {
const a = spaces[i];
const b = spaces[j];
// convert A to B
convert(vec, a, b, tmp);
// convert B to OKLCH
convert(tmp, b, OKLCH, tmp);
// gamut map OKLCH
gamutMapOKLCH(tmp, sRGBGamut, sRGB, tmp);
}
}
}
// benchmark for EOK
// for (let i = 0; i < 1000; i++) {
// for (let vec of vecs) {
// deltaEOK(vec, [0, 0.25, 1]);
// }
// }
// console.timeEnd("bench");