-
Notifications
You must be signed in to change notification settings - Fork 6
/
benchmark.ts
32 lines (30 loc) · 1.16 KB
/
benchmark.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
import Benchmark from 'benchmark'
const suite = new Benchmark.Suite();
import isChinese from './';
const chars1000 = '扁担宽,板凳长,扁担'.repeat(100)
const chars1000WithS = '扁担宽,板凳长,扁担'.repeat(100) + 's'
suite
.add('isChinese("扁担宽,板凳长,扁担想绑在板凳上。")', function () {
isChinese("扁担宽,板凳长,扁担想绑在板凳上。");
})
.add('isChinese("ss扁担宽,板凳长,扁担想绑在板凳上。")', function () {
isChinese("ss扁担宽,板凳长,扁担想绑在板凳上。");
})
.add('isChinese("扁担宽,板凳长,扁担想绑在板凳上。ss")', function () {
isChinese("扁担宽,板凳长,扁担想绑在板凳上。ss");
})
.add('isChinese(chars1000) true', function () {
isChinese(chars1000);
})
.add('isChinese(chars1000WithAscii) false', function () {
isChinese(chars1000WithS);
})
// add listeners
.on('cycle', function (event: any) {
console.log(String(event.target));
})
.on('complete', function (this: Benchmark.Suite) {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });