-
Notifications
You must be signed in to change notification settings - Fork 7
/
benchmark.js
69 lines (66 loc) · 1.92 KB
/
benchmark.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import b from 'benny';
import * as blurhash from 'blurhash';
import { decodeBlurHash } from './index.js';
const characters =
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~';
function randomBlurHash() {
let result = '|EHV6n';
for (var i = 0; i < 160; i++) {
result += characters.charAt(
Math.floor(Math.random() * characters.length),
);
}
return result;
}
b.suite(
'fast-blurhash vs blurhash.decode 32x32',
b.add('blurhash.decode', () => {
const blurHash = randomBlurHash();
return () => blurhash.decode(blurHash, 32, 32);
}),
b.add('fast-blurhash', () => {
const blurHash = randomBlurHash();
return () => decodeBlurHash(blurHash, 32, 32);
}),
b.cycle(),
b.complete(),
);
b.suite(
'fast-blurhash vs blurhash.decode 64x64',
b.add('blurhash.decode', () => {
const blurHash = randomBlurHash();
return () => blurhash.decode(blurHash, 64, 64);
}),
b.add('fast-blurhash 32x32', () => {
const blurHash = randomBlurHash();
return () => decodeBlurHash(blurHash, 64, 64);
}),
b.cycle(),
b.complete(),
);
b.suite(
'fast-blurhash vs blurhash.decode 100x50',
b.add('blurhash.decode', () => {
const blurHash = randomBlurHash();
return () => blurhash.decode(blurHash, 100, 50);
}),
b.add('fast-blurhash', () => {
const blurHash = randomBlurHash();
return () => decodeBlurHash(blurHash, 100, 50);
}),
b.cycle(),
b.complete(),
);
b.suite(
'fast-blurhash vs blurhash.decode 640x480',
b.add('blurhash.decode', () => {
const blurHash = randomBlurHash();
return () => blurhash.decode(blurHash, 640, 480);
}),
b.add('fast-blurhash', () => {
const blurHash = randomBlurHash();
return () => decodeBlurHash(blurHash, 640, 480);
}),
b.cycle(),
b.complete(),
);