2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-09-02 17:07:11 -04:00
|
|
|
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 {
|
2019-05-23 12:28:29 -04:00
|
|
|
/** 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 {
|
2020-02-25 09:14:27 -05:00
|
|
|
const res = sendSync("op_now") as NowResponse;
|
2019-08-26 08:50:21 -04:00
|
|
|
return res.seconds * 1e3 + res.subsecNanos / 1e6;
|
2019-02-02 01:27:42 -05:00
|
|
|
}
|
|
|
|
}
|