diff options
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 14 |
1 files changed, 11 insertions, 3 deletions
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 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 } + const response: RunnerApi.SubmitResponse.Body = { + result, + executionTime, + apiTime, + } res.send(response) }) .listen(PORT) |
