mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: use Bun.nanoseconds() over performance.now()
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import path from 'path';
|
||||
|
||||
const traceSync = <T>(prefix: string, fn: () => T): T => {
|
||||
const start = performance.now();
|
||||
const start = Bun.nanoseconds();
|
||||
const result = fn();
|
||||
const end = performance.now();
|
||||
console.log(`${prefix}: ${(end - start).toFixed(3)}ms`);
|
||||
const end = Bun.nanoseconds();
|
||||
console.log(`${prefix}: ${((end - start) / 1e6).toFixed(3)}ms`);
|
||||
return result;
|
||||
};
|
||||
export { traceSync };
|
||||
|
||||
const traceAsync = async <T>(prefix: string, fn: () => Promise<T>): Promise<T> => {
|
||||
const start = performance.now();
|
||||
const start = Bun.nanoseconds();
|
||||
const result = await fn();
|
||||
const end = performance.now();
|
||||
console.log(`${prefix}: ${(end - start).toFixed(3)}ms`);
|
||||
const end = Bun.nanoseconds();
|
||||
console.log(`${prefix}: ${((end - start) / 1e6).toFixed(3)}ms`);
|
||||
return result;
|
||||
};
|
||||
export { traceAsync };
|
||||
@@ -28,10 +28,10 @@ const task = <T>(importMetaPath: string, fn: () => Promise<T>, customname: strin
|
||||
const taskName = customname ?? path.basename(importMetaPath, path.extname(importMetaPath));
|
||||
return async () => {
|
||||
console.log(`🏃 [${taskName}] Start executing`);
|
||||
const start = performance.now();
|
||||
const start = Bun.nanoseconds();
|
||||
await fn();
|
||||
const end = performance.now();
|
||||
console.log(`✅ [${taskName}] Executed successfully: ${(end - start).toFixed(3)}ms`);
|
||||
const end = Bun.nanoseconds();
|
||||
console.log(`✅ [${taskName}] Executed successfully: ${((end - start) / 1e6).toFixed(3)}ms`);
|
||||
|
||||
return { start, end, taskName } as TaskResult;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user