feat: add benchmark settings panel
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 1m59s

This commit is contained in:
2024-05-01 23:05:04 +02:00
parent 8bf2958e1d
commit d9afec5bf6
39 changed files with 1253 additions and 741 deletions

View File

@ -43,7 +43,6 @@
? filterInputs(node.tmp.type.inputs)
: undefined;
$: store = node ? createStore(node.props, nodeDefinition) : undefined;
$: console.log(nodeDefinition, store);
let lastPropsHash = "";
function updateNode() {

View File

@ -0,0 +1,88 @@
<script lang="ts">
import localStore from "$lib/helpers/localStore";
import { Integer } from "@nodes/ui";
import { writable } from "svelte/store";
export let run: () => Promise<any>;
let isRunning = false;
let amount = localStore<number>("nodes.benchmark.samples", 500);
let samples = 0;
let warmUp = writable(0);
let warmUpAmount = 10;
let state = "";
let result = "";
const copyContent = async (text: string) => {
try {
await navigator.clipboard.writeText(text);
} catch (err) {
console.error("Failed to copy: ", err);
}
};
async function benchmark() {
if (isRunning) return;
isRunning = true;
samples = 0;
$warmUp = 0;
await new Promise((r) => setTimeout(r, 100));
// warm up
for (let i = 0; i < warmUpAmount; i++) {
await run();
$warmUp = i + 1;
}
let results = [];
// perform run
for (let i = 0; i < $amount; i++) {
const a = performance.now();
await run();
samples = i;
const b = performance.now();
results.push(b - a);
console.log(b - a);
}
result = results.join(" ");
}
</script>
{state}
<div class="wrapper" class:running={isRunning}>
{#if isRunning}
<p>WarmUp ({$warmUp}/{warmUpAmount})</p>
<progress value={$warmUp} max={warmUpAmount}
>{Math.floor(($warmUp / warmUpAmount) * 100)}%</progress
>
<p>Progress ({samples}/{$amount})</p>
<progress value={samples} max={$amount}
>{Math.floor((samples / $amount) * 100)}%</progress
>
{#if result}
<textarea readonly>{result}</textarea>
<div>
<button on:click={() => copyContent(result)}>Copy</button>
<button on:click={() => (isRunning = false)}>reset</button>
</div>
{/if}
{:else}
<label for="bench-samples">Samples</label>
<Integer id="bench-sample" bind:value={$amount} max={1000} />
<button on:click={benchmark} disabled={isRunning}> start </button>
{/if}
</div>
<style>
.wrapper {
padding: 1em;
display: flex;
flex-direction: column;
gap: 1em;
}
</style>

View File

@ -0,0 +1,53 @@
<script lang="ts">
import type { Scene } from "three";
import { OBJExporter } from "three/addons/exporters/OBJExporter.js";
import { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
import FileSaver from "file-saver";
// Download
const download = (
data: string,
name: string,
mimetype: string,
extension: string,
) => {
if (typeof data !== "string") data = JSON.stringify(data);
const blob = new Blob([data], { type: mimetype + ";charset=utf-8" });
FileSaver.saveAs(blob, name + "." + extension);
};
// export const json = (data, name = 'default') => {
// download(JSON.stringify(data), name, 'application/json', 'json');
// };
//
// export const obj = (data, name = 'default') => {
// };
export let scene: Scene;
function exportGltf() {
const exporter = new GLTFExporter();
exporter.parse(
scene,
(gltf) => {
// download .gltf file
download(gltf, "plant", "text/plain", "gltf");
},
(err) => {
console.log(err);
},
);
}
function exportObj() {
const exporter = new OBJExporter();
const result = exporter.parse(scene);
// download .obj file
download(result, "plant", "text/plain", "obj");
}
</script>
<div class="p-2">
<button on:click={exportObj}> export obj </button>
<button on:click={exportGltf}> export gltf </button>
</div>

View File

@ -4,10 +4,11 @@
export let keymap: ReturnType<typeof createKeyMap>;
const keys = keymap?.keys;
export let title = "Keymap";
</script>
<div class="wrapper">
<h3>Editor</h3>
<h3>{title}</h3>
<section>
{#each $keys as key}