flaska/benchmark/strings_v2.mjs

45 lines
923 B
JavaScript
Raw Permalink Normal View History

2024-11-02 12:44:54 +00:00
import { summary, run, bench } from 'mitata';
import { FlaskaRouter } from "../flaska.mjs";
// Warmup (de-optimize `bench()` calls)
bench('noop', () => { });
bench('noop2', () => { });
function padStart(length) {
return ''.padStart(length * 2)
}
const spaces = ''.padStart(256)
function strSlice(length) {
return spaces.slice(0, length)
}
function strSubstring(length) {
return spaces.substring(0, length)
}
const testData = new Array(100000)
for (let i = 0; i < testData.length; i++) {
testData[i] = Math.round(Math.random() * 200)
}
let func = [padStart, strSlice, strSubstring];
for (let fun of func) {
console.log(`--- warming up ${fun.name || 'mapl'} ---`)
for (var i = 0; i < 100; i++) {
testData.map(fun)
}
}
summary(() => {
func.forEach(function(fun) {
// console.log(tests, fun, tests.map(fun))
bench(fun.name, function() {
return testData.map(fun)
})
})
})
run();