Skip to content

Commit

Permalink
Use performance.now instead of Date.now (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Jul 13, 2024
1 parent fe50c60 commit 5342e20
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-seahorses-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hereby": minor
---

Use `performance.now` instead of `Date.now`
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"no-inner-declarations": "off",
"no-undef": "off",
"no-unused-vars": "off",
"no-restricted-globals": ["error", "console", "process"],
"no-restricted-globals": ["error", "console", "process", "Date"],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/no-import-type-side-effects": "error",
Expand Down
5 changes: 3 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path";
import { performance } from "node:perf_hooks";
import { types } from "node:util";

import pc from "picocolors";
Expand Down Expand Up @@ -59,7 +60,7 @@ async function mainWorker(d: D) {
const taskNames = tasks.map((task) => pc.blue(task.options.name)).join(", ");
d.log(`Using ${pc.yellow(d.simplifyPath(herebyfilePath))} to run ${taskNames}`);

const start = Date.now();
const start = performance.now();

let errored = false;
try {
Expand All @@ -72,7 +73,7 @@ async function mainWorker(d: D) {
// so we don't end up with an unflushed output.
d.setExitCode(1);
} finally {
const took = Date.now() - start;
const took = performance.now() - start;
d.log(`Completed ${taskNames}${errored ? pc.red(" with errors") : ""} in ${d.prettyMilliseconds(took)}`);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/cli/runner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { performance } from "node:perf_hooks";

import pc from "picocolors";

import type { Task } from "../index.js";
Expand Down Expand Up @@ -58,7 +60,7 @@ export class Runner {
}

protected onTaskStart(task: Task): void {
this._startTimes.set(task, Date.now());
this._startTimes.set(task, performance.now());

if (this._errored) {
return; // Skip logging.
Expand All @@ -72,7 +74,7 @@ export class Runner {
return; // Skip logging.
}

const took = Date.now() - this._startTimes.get(task)!;
const took = performance.now() - this._startTimes.get(task)!;
this._d.log(`Finished ${pc.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`);
}

Expand All @@ -82,7 +84,7 @@ export class Runner {
}

this._errored = true;
const took = Date.now() - this._startTimes.get(task)!;
const took = performance.now() - this._startTimes.get(task)!;
this._d.error(`Error in ${pc.red(task.options.name)} in ${this._d.prettyMilliseconds(took)}\n${e}`);
}
}

0 comments on commit 5342e20

Please sign in to comment.