2024-03-06 14:01:07 +01:00
|
|
|
<script lang="ts">
|
2024-04-10 14:27:23 +02:00
|
|
|
import Grid from "$lib/grid";
|
2024-04-15 22:13:43 +02:00
|
|
|
import GraphInterface from "$lib/graph-interface";
|
2024-03-19 16:41:15 +01:00
|
|
|
import { MemoryRuntimeExecutor } from "$lib/runtime-executor";
|
2024-04-15 18:46:34 +02:00
|
|
|
import { RemoteNodeRegistry } from "$lib/node-registry";
|
2024-04-10 15:40:01 +02:00
|
|
|
import * as templates from "$lib/graph-templates";
|
2024-04-10 21:57:03 +02:00
|
|
|
import type { Graph } from "@nodes/types";
|
2024-04-15 18:46:34 +02:00
|
|
|
import { decode, encode } from "$lib/helpers/flat_tree";
|
|
|
|
import { decodeFloat } from "$lib/helpers/encode";
|
|
|
|
|
|
|
|
globalThis.decode = decode;
|
|
|
|
globalThis.encode = encode;
|
2024-03-06 18:31:06 +01:00
|
|
|
|
2024-04-10 14:27:23 +02:00
|
|
|
const nodeRegistry = new RemoteNodeRegistry("http://localhost:3001");
|
2024-03-19 16:41:15 +01:00
|
|
|
const runtimeExecutor = new MemoryRuntimeExecutor(nodeRegistry);
|
|
|
|
|
2024-04-10 21:57:03 +02:00
|
|
|
let res = "2";
|
|
|
|
let time = 0;
|
2024-03-19 16:56:42 +01:00
|
|
|
|
2024-04-10 15:40:01 +02:00
|
|
|
let graph = localStorage.getItem("graph")
|
|
|
|
? JSON.parse(localStorage.getItem("graph")!)
|
|
|
|
: templates.grid(3, 3);
|
2024-03-19 16:56:42 +01:00
|
|
|
|
2024-04-10 21:57:03 +02:00
|
|
|
function handleResult(event: CustomEvent<Graph>) {
|
|
|
|
let a = performance.now();
|
2024-04-15 18:46:34 +02:00
|
|
|
let _res: any = runtimeExecutor.execute(event.detail);
|
|
|
|
if (_res instanceof Int32Array) {
|
2024-04-15 22:13:43 +02:00
|
|
|
const f = decodeFloat(_res[0], _res[1]);
|
|
|
|
res = Math.round(f * 100_000) / 100_000;
|
2024-04-15 18:46:34 +02:00
|
|
|
} else {
|
|
|
|
res = _res;
|
|
|
|
}
|
2024-04-10 21:57:03 +02:00
|
|
|
time = performance.now() - a;
|
2024-04-10 15:40:01 +02:00
|
|
|
console.log(res);
|
|
|
|
}
|
2024-03-06 18:31:06 +01:00
|
|
|
|
2024-04-10 21:57:03 +02:00
|
|
|
function handleSave(event: CustomEvent<Graph>) {
|
2024-04-10 15:40:01 +02:00
|
|
|
localStorage.setItem("graph", JSON.stringify(event.detail));
|
|
|
|
}
|
2024-03-06 14:01:07 +01:00
|
|
|
</script>
|
|
|
|
|
2024-04-10 14:27:23 +02:00
|
|
|
<div class="wrapper">
|
2024-04-15 18:46:34 +02:00
|
|
|
<header>
|
|
|
|
header
|
|
|
|
<button
|
|
|
|
on:click={() => {
|
|
|
|
graph = templates.grid(10, 10);
|
|
|
|
}}>grid stress-test</button
|
|
|
|
>
|
|
|
|
</header>
|
2024-04-10 14:27:23 +02:00
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Cell>
|
2024-04-10 21:57:03 +02:00
|
|
|
result: {res}
|
|
|
|
<br />
|
|
|
|
time: {time}ms
|
2024-04-10 15:40:01 +02:00
|
|
|
</Grid.Cell>
|
|
|
|
<Grid.Cell>
|
|
|
|
{#key graph}
|
2024-04-10 21:57:03 +02:00
|
|
|
<GraphInterface
|
2024-04-10 15:40:01 +02:00
|
|
|
registry={nodeRegistry}
|
|
|
|
{graph}
|
|
|
|
on:result={handleResult}
|
|
|
|
on:save={handleSave}
|
|
|
|
/>
|
|
|
|
{/key}
|
2024-04-10 14:27:23 +02:00
|
|
|
</Grid.Cell>
|
|
|
|
</Grid.Row>
|
2024-03-06 14:01:07 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2024-04-10 14:27:23 +02:00
|
|
|
header {
|
|
|
|
border-bottom: solid thin white;
|
2024-03-06 14:01:07 +01:00
|
|
|
}
|
|
|
|
|
2024-03-20 02:17:58 +01:00
|
|
|
.wrapper {
|
2024-04-10 14:27:23 +02:00
|
|
|
height: 100vh;
|
|
|
|
width: 100vw;
|
|
|
|
color: white;
|
|
|
|
display: grid;
|
|
|
|
grid-template-rows: 50px 1fr;
|
|
|
|
}
|
|
|
|
|
2024-03-06 14:01:07 +01:00
|
|
|
:global(html) {
|
|
|
|
background: rgb(13, 19, 32);
|
|
|
|
background: linear-gradient(
|
|
|
|
180deg,
|
|
|
|
rgba(13, 19, 32, 1) 0%,
|
|
|
|
rgba(8, 12, 21, 1) 100%
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
:global(body) {
|
|
|
|
margin: 0;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
</style>
|