From 8482c4c6ccf9f9545209b28f861f551bc5805c37 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Thu, 11 May 2023 13:29:23 +0200 Subject: [PATCH] use hrtime instead of date --- example/test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/example/test.ts b/example/test.ts index c486b9d..241c2ef 100644 --- a/example/test.ts +++ b/example/test.ts @@ -1,14 +1,16 @@ import { Status } from "https://deno.land/std@0.186.0/http/http_status.ts"; +import { hrtime } from "https://deno.land/std@0.177.0/node/process.ts"; +import { round } from "https://deno.land/x/math@v1.1.0/mod.ts"; import { HTTPServer } from "../mod.ts"; const httpServer = new HTTPServer(); httpServer.middleware(async (req, done) => { - const started = Date.now(); + const started = hrtime(); console.log(`${req.method} - ${req.ip()} - ${req.path}`); await done(); - const processTime = Date.now() - started; - console.log(`Processed in ${processTime}ms`); + const processTime = hrtime(started); + console.log(`Processed in ${round((processTime[0] * 1000000000 + processTime[1]) / 1000000, 2)}ms`); }); httpServer.error((req, _rep) => {