This commit is contained in:
Kim Ravn Hansen
2025-09-22 16:52:15 +02:00
parent f8bf42a68e
commit 30a0842aa1
6 changed files with 1130 additions and 43 deletions

41
bench.js Executable file
View File

@@ -0,0 +1,41 @@
function dataset() {
return new Array(4000).fill().map(() => "fusse".repeat(5));
}
const simCount = 100_000;
const start = Date.now();
const target = "not found";
for (let sim = 0; sim < simCount; sim++) {
const ds = dataset();
// const len = ds.length;
// for (let i = 0; i < len; i++) {
// // pretend to do work on the data elements
// const el = ds[i];
// if (el === target) {
// console.log("foo");
// }
// }
// ds.forEach((el) => {
// if (el === target) {
// console.log("foo");
// }
// });
while (ds.length > 0) {
let el = ds.pop();
if (el === target) {
console.log("foo");
}
}
}
console.log("time: %f msec", Date.now() - start);
// for-loop : 8568 msec
// .forEach : 8551 msec
// pop() : 8765 msec