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 --- package-lock.json | 8 ++++---- package.json | 2 +- src/index.ts | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index c555644..02e49bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@tinyhttp/cors": "2.0.0", "@tinyhttp/logger": "1.3.0", "milliparsec": "2.2.1", - "slam-types": "git://github.com/jantuomi/slam-types.git#441a72c", + "slam-types": "git://github.com/jantuomi/slam-types.git#9de4a1e", "tmp": "0.2.1", "tsm": "2.2.1" }, @@ -2910,7 +2910,7 @@ }, "node_modules/slam-types": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/jantuomi/slam-types.git#441a72c04cfc61dfead5cad37202a1da87a44499", + "resolved": "git+ssh://git@github.com/jantuomi/slam-types.git#9de4a1ee520063025a9b2cd592a364e28cdd24dc", "license": "ISC" }, "node_modules/slash": { @@ -5265,8 +5265,8 @@ "dev": true }, "slam-types": { - "version": "git+ssh://git@github.com/jantuomi/slam-types.git#441a72c04cfc61dfead5cad37202a1da87a44499", - "from": "slam-types@git://github.com/jantuomi/slam-types.git#441a72c" + "version": "git+ssh://git@github.com/jantuomi/slam-types.git#9de4a1ee520063025a9b2cd592a364e28cdd24dc", + "from": "slam-types@git://github.com/jantuomi/slam-types.git#9de4a1e" }, "slash": { "version": "3.0.0", diff --git a/package.json b/package.json index dab0e1a..d139504 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@tinyhttp/cors": "2.0.0", "@tinyhttp/logger": "1.3.0", "milliparsec": "2.2.1", - "slam-types": "git://github.com/jantuomi/slam-types.git#441a72c", + "slam-types": "git://github.com/jantuomi/slam-types.git#9de4a1e", "tmp": "0.2.1", "tsm": "2.2.1" }, 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