Skip to content

Commit 29f2c7e

Browse files
committed
add client side execution time tracking
1 parent acb62e0 commit 29f2c7e

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

clients/java/src/main/java/com/hax/adventofcode/MessageHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Arrays;
44
import java.util.concurrent.CompletableFuture;
5+
import java.util.concurrent.TimeUnit;
56

67
public class MessageHandler {
78

@@ -26,9 +27,12 @@ public void handleMessage(String message) {
2627
String name = messagearray[3];
2728
String data = String.join(":",Arrays.copyOfRange(messagearray, 4, messagearray.length));
2829
System.out.println("Running solution "+name+" with runid "+runid);
29-
CompletableFuture.supplyAsync(() ->
30-
solutionRunner.runClass(name, data)).thenAccept((result) -> {
31-
client.send("aocclient:java:result:"+runid+":"+ Arrays.toString(result));
30+
CompletableFuture.supplyAsync(() -> {
31+
long start = System.nanoTime();
32+
String[] result = solutionRunner.runClass(name, data);
33+
long end = System.nanoTime();
34+
client.send("aocclient:java:result:"+runid+":"+ (end-start)/1e6 +":"+ Arrays.toString(result));
35+
return result;
3236
});
3337
}
3438
}

clients/typescript/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ function startWebsocket() {
1717
const data = split.slice(4).join(':');
1818
const solution = split[3];
1919
console.log(`running ${solution} with runid ${runid}`);
20+
const startTime = performance.now();
2021
const result = await runner.run(solution, data);
22+
const time = performance.now() - startTime;
2123
console.log(`result for ${solution} with runid ${runid}: ${result}`)
22-
ws.send(`aocclient:ts:result:${runid}:[${result[0]}, ${result[1]}]`);
24+
ws.send(`aocclient:ts:result:${runid}:${time}:[${result[0]}, ${result[1]}]`);
2325
}
2426
});
2527

server/apiserver.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class ApiServer {
1212
const { socket: ws, response } = Deno.upgradeWebSocket(req);
1313

1414
ws.onmessage = (e) => {
15-
const msg = e.data.toString();
15+
const msg: string = e.data.toString();
1616
const split = msg.split(':');
1717

1818
// Code Runner Requests
@@ -30,10 +30,11 @@ export default class ApiServer {
3030
}
3131
if (messagedata === 'result') {
3232
const id = Number(split[3]);
33-
const result = split.slice(4).join(':');
34-
console.log(`${clientname} got result ${result} with runid ${id}`)
33+
const time = Number(split[4]);
34+
const result = split.slice(5).join(':');
35+
console.log(`${clientname} got result ${result} with runid ${id} in ${time}ms`);
3536
const run = webserver.runs.find(run => run[0] === id)!;
36-
run[1].send(JSON.stringify({ type: 'result', data: result, time: new Date().getTime() - run[2] }));
37+
run[1].send(JSON.stringify({ type: 'result', data: result, time: time }));
3738
}
3839
if (messagedata === 'solutions') {
3940
webserver.solutions = webserver.solutions.filter(solution => solution[0] !== clientname)

server/webserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ApiServer from "./apiserver.ts";
55
export default class WebServer {
66
solutions: [string, string[]][] = [];
77
clients: WebSocket[] = [];
8-
runs: [number, WebSocket, number][] = [];
8+
runs: [number, WebSocket][] = [];
99

1010
startServer(apiserver: ApiServer) {
1111
const app = new Application();
@@ -30,7 +30,7 @@ export default class WebServer {
3030

3131
if (!(input && solution)) return;
3232
const id = Math.round(Math.random() * 100000)
33-
this.runs.push([id, ws, new Date().getTime()]);
33+
this.runs.push([id, ws]);
3434
const clientname = this.solutions.find(solutiondata => solutiondata[1].includes(solution))![0];
3535
console.log(`running ${solution} with runid ${id} on runner ${clientname}`)
3636
const coderunner = apiserver.clients.find(client => client[0] === clientname);

0 commit comments

Comments
 (0)