-
Notifications
You must be signed in to change notification settings - Fork 3
/
bench.ts
61 lines (55 loc) · 1.52 KB
/
bench.ts
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
61
import fs from 'fs';
import benchmark from 'benchmark';
import { PNG } from 'pngjs';
// tslint:disable-next-line:import-name
import * as imageCodecTxi from '.';
import { join } from 'path';
const inputPNG = PNG.sync.read(
fs.readFileSync(join(__dirname, 'src', '__test__', 'transparency-rgba.png')),
);
const inputImage = {
data: new Uint8ClampedArray(inputPNG.data),
width: inputPNG.width,
height: inputPNG.height,
};
const suite = new benchmark.Suite();
suite
.add('RGBA8888', () => {
imageCodecTxi.encode(inputImage, {
rle: 'auto',
outputFormat: imageCodecTxi.TXIOutputFormat.RGBA8888,
});
})
.add('RGBA4444', () => {
imageCodecTxi.encode(inputImage, {
rle: 'auto',
outputFormat: imageCodecTxi.TXIOutputFormat.RGBA4444,
});
})
.add('RGBA6666', () => {
imageCodecTxi.encode(inputImage, {
rle: 'auto',
outputFormat: imageCodecTxi.TXIOutputFormat.RGBA6666,
});
})
.add('RGB565', () => {
imageCodecTxi.encode(inputImage, {
rle: 'auto',
outputFormat: imageCodecTxi.TXIOutputFormat.RGB565,
});
})
.add('A8', () => {
imageCodecTxi.encode(inputImage, {
rle: 'auto',
outputFormat: imageCodecTxi.TXIOutputFormat.A8,
});
})
.on('cycle', (event: any) => {
console.log(String(event.target));
console.log(`${(event.target.stats.mean * 1000).toFixed(2)} ms/run`);
})
.on('error', (event: any) => {
console.error(`Error running ${event.target.name}:`);
console.error(event.target.error);
})
.run({ async: true });