deno/cli/js/performance.ts

22 lines
577 B
TypeScript
Raw Normal View History

2020-01-02 20:13:47 +00:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync } from "./ops/dispatch_json.ts";
2019-08-26 12:50:21 +00:00
interface NowResponse {
seconds: number;
subsecNanos: number;
}
2019-02-02 06:27:42 +00:00
export class Performance {
/** Returns a current time from Deno's start in milliseconds.
*
* Use the flag --allow-hrtime return a precise value.
2019-02-02 06:27:42 +00:00
*
* const t = performance.now();
* console.log(`${t} ms since start!`);
*/
now(): number {
2020-02-25 14:14:27 +00:00
const res = sendSync("op_now") as NowResponse;
2019-08-26 12:50:21 +00:00
return res.seconds * 1e3 + res.subsecNanos / 1e6;
2019-02-02 06:27:42 +00:00
}
}