From 12f1e04c9375bb399285d91bf16a44cc11080551 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 8 Feb 2022 17:15:18 +0200 Subject: Add executionTime, apiTime to response --- src/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/index.ts b/src/index.ts index 88a9a14..af61d0f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import tmp from "tmp" import fs from "fs" import { RunnerApi } from "slam-types" import { cors } from "@tinyhttp/cors" +import { hrtime } from "process" const exec = promisify(cb_exec) const app = new App() @@ -40,13 +41,20 @@ app return res.sendStatus(400) } + const apiTimeHandle = hrtime() const { name: sourceFile } = tmp.fileSync() as { name: string } fs.writeFileSync(sourceFile, body.source) - + const executionTimeHandle = hrtime() const result = await interpretFile(sourceFile) - fs.rmSync(sourceFile) - - const response: RunnerApi.SubmitResponse.Body = { result } + const executionTime = Math.round(hrtime(executionTimeHandle)[1] / 1000) + fs.rm(sourceFile, () => void 0) + const apiTime = Math.round(hrtime(apiTimeHandle)[1] / 1000) + + const response: RunnerApi.SubmitResponse.Body = { + result, + executionTime, + apiTime, + } res.send(response) }) .listen(PORT) -- cgit v1.3