-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-b64.html
75 lines (63 loc) · 2.33 KB
/
demo-b64.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Techmino Replay Parser Demo</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<h1>Techmino Replay Parser Demo</h1>
<textarea type="file" id="input" placeholder="Paste base-64 replay here..."></textarea> <br>
<button type="button" id="go">Parse!</button>
<button type="button" id="bench">Benchmark x1000</button>
<hr>
<p>
Result:
(<span id="time"></span> ms)
</p>
<p id="output"></p>
<script type="module">
import { parseReplayFromRepString } from './dist/index.js';
/** @type {HTMLTextAreaElement} */
const input = document.getElementById('input');
const btn = document.getElementById('go');
const bench = document.getElementById('bench');
const output = document.getElementById('output');
const time = document.getElementById('time');
// const { parseReplayFromRepString } = window.TechminoReplayParser;
async function main() {
const startTime = performance.now();
if(!input) {
throw new Error('Input element not found');
}
const base64 = input.value.trim();
if (base64.length === 0) {
return;
}
const parsed = await parseReplayFromRepString(base64);
time.textContent = (performance.now() - startTime);
output.textContent = JSON.stringify(parsed);
}
async function benchFn() {
const ITERATIONS = 1000;
const startTime = performance.now();
if(!input) {
throw new Error('Input element not found');
}
let base64 = input.value.trim();
if (base64.length === 0) {
return;
}
let parsed;
for(let i = 0; i < ITERATIONS; i++) {
parsed = await parseReplayFromRepString(base64);
}
time.textContent = `${ITERATIONS} x ${(performance.now() - startTime) / ITERATIONS}`;
output.textContent = JSON.stringify(parsed);
}
btn.addEventListener('click', main);
bench.addEventListener('click', benchFn);
</script>
</body>
</html>