54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
const { LoggingBase } = require("./out/index.js");
|
|
let results = {};
|
|
|
|
function benchmark(name, count, runner) {
|
|
console.profile(name);
|
|
const start = process.hrtime.bigint()
|
|
|
|
runner(count);
|
|
|
|
const diffNS = process.hrtime.bigint() - start;
|
|
const diffMS = Number(diffNS / 1000n / 1000n);
|
|
console.profileEnd(name)
|
|
|
|
results[name]= {
|
|
count,
|
|
time: diffMS,
|
|
timePerI: (diffMS / count).toFixed(4)
|
|
}
|
|
}
|
|
|
|
benchmark("simple", 10000000, (cnt) => {
|
|
const l = new LoggingBase({
|
|
console: false
|
|
});
|
|
for (let i = 0; i < cnt; i++) {
|
|
l.log("simple log")
|
|
}
|
|
})
|
|
|
|
benchmark("complex", 1000000, (cnt) => {
|
|
const l = new LoggingBase({
|
|
console: false
|
|
});
|
|
for (let i = 0; i < cnt; i++) {
|
|
l.log("complex log", {
|
|
a: 1,
|
|
b: {
|
|
c:"test"
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
benchmark("very long", 10000000, (cnt) => {
|
|
const l = new LoggingBase({
|
|
console: false
|
|
});
|
|
const longText = "complex log".repeat(100);
|
|
for (let i = 0; i < cnt; i++) {
|
|
l.log(longText)
|
|
}
|
|
})
|
|
|
|
console.table(results) |