-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbenchmark.js
27 lines (22 loc) · 1007 Bytes
/
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
const { performance } = require("perf_hooks");
const split = require("./index");
// when a Javascript engine notices a function being called frequently,
// it will pass it through the optimizer. For consistency, we'd like to make
// sure that happens before we start measuring.
for (let i = 0; i < 1000; i++) {
split("warm up");
}
// benchmark a simple string, with no unicode combining characters
const simpleStart = performance.now();
for (let i = 0; i < 10000; i++) {
split("hello world");
}
const simpleEnd = performance.now();
console.log(`simple string: ${simpleEnd - simpleStart}ms`);
// benchmark a complex string with several unicode combining characters
const complexStart = performance.now();
for (let i = 0; i < 10000; i++) {
split("Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞");
}
const complexEnd = performance.now();
console.log(`complex string: ${complexEnd - complexStart}ms`);