2019-02-02 09:27:42 +03:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-08-24 13:20:48 -07:00
|
|
|
import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
|
|
|
|
import { assert } from "./util";
|
2019-02-02 09:27:42 +03:00
|
|
|
|
|
|
|
export class Performance {
|
2019-05-23 19:28:29 +03:00
|
|
|
/** Returns a current time from Deno's start in milliseconds.
|
|
|
|
*
|
|
|
|
* Use the flag --allow-hrtime return a precise value.
|
2019-02-02 09:27:42 +03:00
|
|
|
*
|
|
|
|
* const t = performance.now();
|
|
|
|
* console.log(`${t} ms since start!`);
|
|
|
|
*/
|
|
|
|
now(): number {
|
2019-08-24 13:20:48 -07:00
|
|
|
const builder = flatbuffers.createBuilder();
|
|
|
|
const inner = msg.Now.createNow(builder);
|
|
|
|
const baseRes = sendSync(builder, msg.Any.Now, inner)!;
|
|
|
|
assert(msg.Any.NowRes === baseRes.innerType());
|
|
|
|
const res = new msg.NowRes();
|
|
|
|
assert(baseRes.inner(res) != null);
|
|
|
|
return res.seconds().toFloat64() * 1e3 + res.subsecNanos() / 1e6;
|
2019-02-02 09:27:42 +03:00
|
|
|
}
|
|
|
|
}
|