diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-02-08 17:15:18 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-02-08 17:15:18 +0200 |
| commit | 12f1e04c9375bb399285d91bf16a44cc11080551 (patch) | |
| tree | 6316f2366942d3e32ff1fe8e6225f19bc26f8bfa /src/index.ts | |
| parent | 29a4d3de2826e14241266e350ff2948537b5d1d5 (diff) | |
Add executionTime, apiTime to response
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) |
