0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/cli/js/performance.ts

23 lines
623 B
TypeScript
Raw Normal View History

2019-02-02 01:27:42 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
2019-08-26 08:50:21 -04:00
interface NowResponse {
seconds: number;
subsecNanos: number;
}
2019-02-02 01:27:42 -05: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 01:27:42 -05:00
*
* const t = performance.now();
* console.log(`${t} ms since start!`);
*/
now(): number {
2019-08-26 08:50:21 -04:00
const res = sendSync(dispatch.OP_NOW) as NowResponse;
return res.seconds * 1e3 + res.subsecNanos / 1e6;
2019-02-02 01:27:42 -05:00
}
}