Skip to content

Commit 8ab37dc

Browse files
committed
bench: replace Math.pow() with exponentiation operator
1 parent ddb5911 commit 8ab37dc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

benchmark/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function outputResults(benchTimeHR) {
9898

9999
const sum = results.reduce(
100100
(previous, current) =>
101-
previous + Math.pow(current[1], 2) + Math.pow(current[0] - mean, 2),
101+
previous + current[1] ** 2 + (current[0] - mean) ** 2,
102102
0
103103
);
104104
const stdev = Math.sqrt(sum / workersAmount);

benchmark/statistics.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const stdev = (sample, meanValue) => {
1515
if (len === 0 || len === 1) return 0;
1616
let sum = 0;
1717
for (let i = 0; i < len; i++) {
18-
sum += Math.pow(sample[i] - meanValue, 2);
18+
sum += (sample[i] - meanValue) ** 2;
1919
}
2020
const variance = sum / len;
2121
return Math.sqrt(variance);
@@ -43,8 +43,8 @@ const combineStdev = (samples, mean, count) => {
4343
for (let i = 0; i < samples.length; i++) {
4444
const sample = samples[i];
4545
sum +=
46-
sample.count * Math.pow(sample.stdev, 2) +
47-
sample.count * Math.pow(sample.mean - mean, 2);
46+
sample.count * sample.stdev ** 2 +
47+
sample.count * (sample.mean - mean) ** 2;
4848
}
4949
return Math.sqrt(sum / count);
5050
};

0 commit comments

Comments
 (0)