-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
34 lines (26 loc) · 763 Bytes
/
utils.js
File metadata and controls
34 lines (26 loc) · 763 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
29
30
31
32
33
34
function generateRandomString(size){
let result = [];
for(let i = 0; i < size; i++){
//let base = [67, 97][Math.floor(Math.random() * 2)];
let charCode = 126 + Math.floor(Math.random() * 8000);
result.push(String.fromCharCode(charCode));
}
return result.join('');
}
function benchmark(fn1, fn2, input, nbIterations){
let timeFn1 = Date.now();
for(let i = 0; i < nbIterations; i++){
fn1(input);
}
timeFn1 = Date.now() - timeFn1;
let timeFn2 = Date.now();
for(let i = 0; i < nbIterations; i++){
fn2(input);
}
timeFn2 = Date.now() - timeFn2;
console.log(`time fn1: ${timeFn1} time fn2: ${timeFn2}`);
}
module.exports = {
generateRandomString,
benchmark
};