-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf-ref.esm.js
58 lines (55 loc) · 1.42 KB
/
perf-ref.esm.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @name perf-ref
* @fileoverview A dummy, set-in-stone program to be used as a reference
* @version 1.0.0
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/perf-ref/}
*/
var version$1 = "1.0.0";
const version = version$1;
const opsPerSec = 183;
function perfRef(seed = 10000) {
const input =
"lorem ipsum 1 dolor sit amet 2, consectetur adipiscing 3 ".repeat(seed);
let lastPositionOfNumOne = 0;
let lastPositionOfNumTwo = 0;
let lastPositionOfNumThree = 0;
const counts = {
ones: 0,
twos: 0,
threes: 0,
};
for (let i = 0, len = input.length; i < len; i++) {
if (input[i] === "1" && !(i % 23)) {
lastPositionOfNumOne = i;
counts.ones++;
} else if (input[i] === "2" && !(i % 7)) {
lastPositionOfNumTwo = i;
counts.twos++;
} else if (input[i] === "3" && !(i % 11)) {
lastPositionOfNumThree = i;
counts.threes++;
}
if (i === 1000) {
continue;
}
}
return [
...new Set(
String(
Math.floor(
+String(
(lastPositionOfNumOne * lastPositionOfNumTwo) /
lastPositionOfNumThree
)
.split("")
.reduce((acc, curr) => curr.charCodeAt(0) + acc, 0)
)
).split("")
),
]
.map((v, i) => +v * Number(Object.values(counts)[i]))
.reduce((acc, curr) => `${curr}${acc}`, "");
}
export { opsPerSec, perfRef, version };