generated from tweakpane/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
126 lines (108 loc) · 3.43 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@0b5vr/tweakpane-plugin-profiler</title>
<link rel="stylesheet" href="https://www.unpkg.com/[email protected]/lib/codemirror.css" />
<link rel="stylesheet" href="https://www.unpkg.com/[email protected]/theme/monokai.css" />
<style>
.CodeMirror {
width: 600px;
height: 600px;
}
</style>
</head>
<body>
<textarea id="textareaEditor">// https://github.com/0b5vr/tweakpane-plugin-profiler
// Ctrl+S or Ctrl+R to apply changes
// == setup tweakpane and the plugin ===============================================================
const pane = new Tweakpane.Pane();
pane.registerPlugin( TweakpaneProfilerBladePlugin );
const profiler = pane.addBlade( {
view: 'profiler',
label: 'profiler',
targetDelta: 1, // 16ms by default
} );
console.log( profiler );
// == random expensive functions ===================================================================
function abuseRandom() {
let sum = 0.0;
for ( let sum = 0; sum < 1E4; sum ++ ) {
sum += Math.random();
}
}
function abuseSin() {
let sum = 0.0;
for ( let sum = 0; sum < 1E4; sum ++ ) {
sum += Math.sin( 1.0 );
}
}
function abuseFind() {
for ( let sum = 0; sum < 1E4; sum ++ ) {
/define/.test( 'undefined' );
}
}
// == update =======================================================================================
let stop = false;
function update() {
if ( stop ) { return; }
// the lambda inside the `profiler.measure` is measured
profiler.measure( 'update', () => {
// the `profiler.measure` can be nested and displayed in a hierarchy
profiler.measure( 'math', () => {
// even more hierarchy
profiler.measure( 'abuseRandom', () => {
abuseRandom();
} );
// another item on the same level
profiler.measure( 'abuseSin', () => {
abuseSin();
} );
} );
// you can use a more classic way as well
profiler.measureStart( 'abuseFind' );
abuseFind();
profiler.measureEnd();
} );
requestAnimationFrame( update );
}
requestAnimationFrame( update );
// == unload handler ===============================================================================
playground.onUnload = () => {
stop = true;
pane.dispose();
};
</textarea>
<script src="https://www.unpkg.com/[email protected]/lib/codemirror.js"></script>
<script src="https://www.unpkg.com/[email protected]/addon/comment/comment.js"></script>
<script src="https://www.unpkg.com/[email protected]/keymap/sublime.js"></script>
<script src="https://www.unpkg.com/[email protected]/mode/javascript/javascript.js"></script>
<script type="module">
import * as Tweakpane from 'https://unpkg.com/[email protected]/dist/tweakpane.js';
import * as TweakpaneProfilerBladePlugin from './dist/tweakpane-plugin-profiler.js';
const textareaEditor = document.getElementById( 'textareaEditor' );
const editor = CodeMirror.fromTextArea( textareaEditor, {
mode: 'javascript',
keyMap: 'sublime',
theme: 'monokai',
lineNumbers: true,
} );
editor.addKeyMap( {
'Ctrl-S': () => {
run();
},
'Ctrl-R': () => {
run();
},
} );
const playground = {
onUnload: () => {},
}
function run() {
playground.onUnload?.();
eval( editor.getValue() );
}
run();
</script>
</body>
</html>