-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.js
More file actions
executable file
·28 lines (25 loc) · 667 Bytes
/
bench.js
File metadata and controls
executable file
·28 lines (25 loc) · 667 Bytes
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
import { SafeToken } from "./dist/index.js";
// auth
const Auth = new SafeToken({
secret: "9494d249ad9fd041f9d052e0d0b9c9e7e45bfc3f",
});
export async function benchSuit(code, runs = 1_000, label) {
const startTime = performance.now();
for (let i = 0; i < runs; i++) {
await code();
}
let totalTime = performance.now() - startTime;
if (label) {
console.log(label + " - Bechmark score");
}
console.log(
`Code took ${totalTime} ms on ${runs} runs with an average of ${
totalTime / runs
} ms per operation`
);
console.log("");
return totalTime;
}
await benchSuit(async () => {
await Auth.verify(await Auth.create());
});