From d989e1e942a77749c31e82296dd6c83a97184fd0 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 8 Feb 2022 17:45:04 +0200 Subject: Show timing info --- src/Editor.tsx | 5 ++++- src/api.ts | 30 ++++++------------------------ 2 files changed, 10 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/Editor.tsx b/src/Editor.tsx index 8cf6901..f549fc8 100644 --- a/src/Editor.tsx +++ b/src/Editor.tsx @@ -87,7 +87,10 @@ const Editor = () => { ) case "success": { - const text = `Output:\n${result.data}` + const apiTimeMillis = (result.data.apiTime / 1000).toFixed(1) + const executionTimeMillis = (result.data.executionTime / 1000).toFixed(1) + const roundtripTime = (result.data.roundtripTime).toFixed(1) + const text = `Output:\n${result.data.result}\nTotal roundtrip time: ${roundtripTime} ms\nServer processing time: ${apiTimeMillis} ms\nExecution time: ${executionTimeMillis} ms` return ( mapSWRResult - -const postSource = async (text: string): Promise => { - const apiResult = await postRequest( - { - baseUrl: RUNNER_API_URL, - path: RunnerApi.SubmitRequest.path, - body: { - source: text, - }, - }, - ) - - switch (apiResult.type) { - case "success": - return { type: "success", data: apiResult.data.result } - case "failed": - return { type: "failed", error: apiResult.error } - case "not_yet_requested": - case "loading": - return apiResult - } -} +export type SubmitResult = APIResult export const useSubmitSource = () => { const [result, setResult] = useState({ type: "not_yet_requested" }) const submitSource = async (text: string) => { try { + const startRoundtripTime = performance.now() setResult({ type: "loading" }) const apiResult = await postRequest( { @@ -115,10 +94,13 @@ export const useSubmitSource = () => { }, }, ) + const endRoundtripTime = performance.now() + const roundtripTime = endRoundtripTime - startRoundtripTime switch (apiResult.type) { case "success": - setResult({ type: "success", data: apiResult.data.result }) + setResult({ type: "success", data: { ...apiResult.data, roundtripTime }}) break + case "failed": setResult({ type: "failed", error: apiResult.error }) break -- cgit v1.3