0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/performance.ts
Ryan Dahl bdc97b3976
Organize dispatch a bit (#2796)
Just some clean up reorganization around flatbuffer/minimal dispatch
code. This is prep for adding a JSON dispatcher.
2019-08-21 20:42:48 -04:00

22 lines
805 B
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
import { assert } from "./util";
export class Performance {
/** Returns a current time from Deno's start in milliseconds.
*
* Use the flag --allow-hrtime return a precise value.
*
* const t = performance.now();
* console.log(`${t} ms since start!`);
*/
now(): number {
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;
}
}