Skip to content

Commit 9ed8102

Browse files
committed
2 parents cecc63f + a708219 commit 9ed8102

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

JavaScript/2-benchmark.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ benchmark.do = (count, retry, tests) => {
2020
}
2121
const end = process.hrtime(begin);
2222
const diff = end[0] * 1e9 + end[1];
23-
const prefix = Array(15 - (diff.toString()).length).join('.');
24-
const suffix = Array(20 - fn.name.length).join('.');
25-
console.log(fn.name + suffix + prefix + diff + ' nanoseconds');
23+
const prefix = '.'.repeat(35 - (diff + fn.name).length);
24+
console.log(fn.name + prefix + diff + ' nanoseconds');
2625
}
27-
2826
};

JavaScript/c-repeat.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const benchmark = require('./2-benchmark.js');
4+
5+
function testArrayJoin() {
6+
return Array(20).join('.');
7+
}
8+
9+
function testRepeat() {
10+
return '.'.repeat(20);
11+
}
12+
13+
benchmark.do(1000000, 3, [
14+
testArrayJoin,
15+
testRepeat,
16+
]);

0 commit comments

Comments
 (0)