Some performance optimizations
This commit is contained in:
54
benchmark.js
Normal file
54
benchmark.js
Normal file
@ -0,0 +1,54 @@
|
||||
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)
|
Reference in New Issue
Block a user