Some optimisations
This commit is contained in:
50
src/benchmark.ts
Normal file
50
src/benchmark.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { Formatted, LoggingBase, LoggingTypes } from "@hibas123/logging";
|
||||
import { once } from "events";
|
||||
import { createWriteStream } from "fs";
|
||||
import { FileAdapter } from "./filewriter";
|
||||
|
||||
let results = {};
|
||||
|
||||
async function benchmark(
|
||||
name: string,
|
||||
count: number,
|
||||
runner: (cnt: number) => Promise<void>
|
||||
) {
|
||||
console.log("Benchmark starting:", name);
|
||||
const start = process.hrtime.bigint();
|
||||
|
||||
await runner(count);
|
||||
|
||||
const diffNS = process.hrtime.bigint() - start;
|
||||
const diffMS = Number(diffNS / BigInt(1000 * 1000));
|
||||
|
||||
console.log("Benchmark ended:", name);
|
||||
|
||||
results[name] = {
|
||||
count,
|
||||
time: diffMS,
|
||||
timePerI: (diffMS / count).toFixed(4),
|
||||
};
|
||||
}
|
||||
|
||||
Promise.resolve().then(async () => {
|
||||
const largeText = "hallowelt!".repeat(250);
|
||||
|
||||
const lg = new LoggingBase({
|
||||
console: false,
|
||||
});
|
||||
const fs = new FileAdapter("logs/benchmark", Number.MAX_SAFE_INTEGER);
|
||||
await lg.addAdapter(fs);
|
||||
|
||||
await benchmark("large data", 100000, async (cnt) => {
|
||||
console.time("Logging");
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
lg.log(largeText);
|
||||
}
|
||||
console.timeEnd("Logging");
|
||||
|
||||
await fs.close();
|
||||
await lg.close();
|
||||
});
|
||||
console.table(results);
|
||||
});
|
Reference in New Issue
Block a user