forked from 0b5vr/tweakpane-plugin-profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (117 loc) · 3.69 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
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@0b5vr/tweakpane-plugin-profiler</title>
<link rel="stylesheet" href="https://www.unpkg.com/codemirror@5.62.3/lib/codemirror.css" />
<link rel="stylesheet" href="https://www.unpkg.com/codemirror@5.62.3/theme/monokai.css" />
<style>
.CodeMirror {
width: 600px;
height: 600px;
}
</style>
<script type="importmap">
{
"imports": {
"tweakpane": "../node_modules/tweakpane/dist/tweakpane.js",
"@tweakpane/core": "../node_modules/@tweakpane/core/dist/index.js",
"tweakpane-plugin-profiler": "./dist/tweakpane-plugin-profiler.js"
}
}
</script>
</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/codemirror@5.62.3/lib/codemirror.js"></script>
<script src="https://www.unpkg.com/codemirror@5.62.3/addon/comment/comment.js"></script>
<script src="https://www.unpkg.com/codemirror@5.62.3/keymap/sublime.js"></script>
<script src="https://www.unpkg.com/codemirror@5.62.3/mode/javascript/javascript.js"></script>
<script type="module">
import * as Tweakpane from 'tweakpane';
import * as TweakpaneProfilerBladePlugin from 'tweakpane-plugin-profiler';
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>