rework option as showInRangeSelector
[dygraphs.git] / tests / dygraph-many-points-benchmark.html
CommitLineData
54425b14 1<!DOCTYPE html>
15b00ba8
JB
2<html>
3 <head>
10494b48 4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
15b00ba8
JB
5 <title>Benchmarking for Plots with Many Points</title>
6 <!--[if IE]>
7 <script type="text/javascript" src="../excanvas.js"></script>
8 <![endif]-->
7e5ddc94
DV
9 <!--
10 For production (minified) code, use:
11 <script type="text/javascript" src="dygraph-combined.js"></script>
12 -->
13 <script type="text/javascript" src="../dygraph-dev.js"></script>
14
15b00ba8
JB
15 </head>
16 <body>
17 <p>Plot which can be easily generated with different numbers of points for
18 benchmarking/profiling and improving performance of dygraphs.</p>
5ecfa608
RK
19 <div id='parameters'>
20 <p>Data to plot:
21 <input type="radio" id="sine" name="group1" value="sine"
0a14b0f9 22 onclick="setDataType(this);" checked> sinusoid function
5ecfa608 23 <input type="radio" id="rand" name="group1" value="rand"
0a14b0f9
AV
24 onclick="setDataType(this);"> random points <br></p>
25 <p>Timestamps:
4c9d65da
DV
26 <input type="radio" id="aligned" name="timestamps" value="aligned" checked> aligned
27 <input type="radio" id="unaligned" name="timestamps" value="unaligned"> unaligned
28 </p>
29 <p>x-axis type:
30 <input type="radio" id="numeric" name="x-axis-type" value="numeric" onclick="setXAxisType(this)" checked> numeric
31 <input type="radio" id="dates" name="x-axis-type" value="date" onclick="setXAxisType(this)"> date/time
0a14b0f9 32 <p>Number of points per series (points):
5ecfa608 33 <input type="text" id="points" size="20"></p>
6f417f78 34 <p>Number of series (series):
5ecfa608 35 <input type="text" id="series" size="20"></p>
6f417f78 36 <p>Roll period (in points, rollPeriod):
5ecfa608 37 <input type="text" id="rollPeriod" size="20"></p>
6f417f78 38 <p>Repetitions (repititions):
5ecfa608
RK
39 <input type="text" id="repetitions" size="20"></p>
40 <input type="button" value="Go!" onclick="updatePlot();">
41 </div>
15b00ba8
JB
42 <br>
43 <br>
44 <div id="plot"></div>
09c17553 45 <div id="message"></div>
f7adb3d7 46 <div id="metrics"></div>
62c2a51e 47 <div id="metaperformance"></div>
15b00ba8
JB
48
49 <script type="text/javascript">
5ecfa608
RK
50 var graph = null;
51 var metrics = null;
a058247d 52 var dataType = "sine";
0a14b0f9 53 var timestamps = "aligned";
4c9d65da 54 var numRuns = 0;
15b00ba8 55
62c2a51e 56 var durations = [];
15b00ba8 57 updatePlot = function() {
09c17553 58 document.getElementById('message').innerHTML = "";
15b00ba8
JB
59 var plotDiv = document.getElementById('plot');
60 plotDiv.innerHTML = 'Redrawing...';
4c9d65da 61 var numeric = document.getElementById('numeric').checked;
15b00ba8 62 var numPoints =
bbba718a 63 parseInt(document.getElementById('points').value);
09c17553 64 var numSeries =
bbba718a 65 parseInt(document.getElementById('series').value);
f7adb3d7
RK
66 var repetitions =
67 parseInt(document.getElementById('repetitions').value);
09c17553 68
15b00ba8 69 var data = [];
4c9d65da
DV
70 var xmin = numeric ? 0.0 : Date.parse("2014/01/01");
71 var xmax = numeric ? 2.0 * Math.PI : Date.parse("2014/12/31");
09c17553 72 var adj = .5;
15b00ba8 73 var delta = (xmax - xmin) / (numPoints - 1);
0a14b0f9 74 var unalignmentDelta = delta / numSeries;
15b00ba8
JB
75
76 for (var i = 0; i < numPoints; ++i) {
77 var x = xmin + delta * i;
09c17553
RK
78 var elem = [ x ];
79 for (var j = 0; j < numSeries; j++) {
a058247d
AR
80 var y;
81 if (dataType == "rand") {
36d73927 82 y = Math.pow(Math.random() - Math.random(), 7);
a058247d
AR
83 } else {
84 y = Math.sin(x + (j * adj));
85 }
09c17553
RK
86 elem.push(y);
87 }
0a14b0f9
AV
88 if (timestamps == "aligned") {
89 data[i] = elem;
90 } else {
91 for (var j = 0; j < numSeries; j++) {
92 var elemCopy = elem.slice(0);
93 elemCopy[0] += unalignmentDelta * j;
94 data[i*numSeries + j] = elemCopy;
95 }
96 }
4c9d65da 97 if (!numeric) data[i][0] = new Date(data[i][0]);
09c17553
RK
98 }
99 var labels = [ "x" ];
100 for (var j = 0; j < numSeries; j++) {
36d73927 101 labels.push("data-set-" + j);
15b00ba8 102 }
15b00ba8 103 var rollPeriod = parseInt(
bbba718a 104 document.getElementById('rollPeriod').value);
7153e001 105 var opts = {labels: labels, rollPeriod: rollPeriod, timingName: "x"};
62c2a51e 106 var millisecondss = [];
f7adb3d7 107 for (var i = 0; i < repetitions; i++) {
5ecfa608
RK
108 if (graph != null) {
109 graph.destroy(); // release memory from prior graph.
110 }
f7adb3d7 111 var start = new Date();
5ecfa608 112 graph = new Dygraph(plotDiv, data, opts);
f7adb3d7 113 var end = new Date();
4c9d65da 114 durations.push([numRuns++, end - start]);
62c2a51e 115 millisecondss.push(end - start);
f7adb3d7
RK
116 }
117 if (repetitions == 1) {
118 document.getElementById('message').innerHTML =
119 "completed in " + (end - start) + " milliseconds.";
120 } else {
a11725ce
AR
121 var avg = 0;
122 for (var i = 0; i < millisecondss.length; i++) {
123 avg+=millisecondss[i];
124 }
125 avg/=millisecondss.length;
f7adb3d7 126 document.getElementById('message').innerHTML =
4c9d65da 127 "Durations: " + millisecondss + "<br>Average: " + avg;
f7adb3d7 128 }
15b00ba8 129
62c2a51e
RK
130 if (durations.length > 0) {
131 var start2 = new Date();
5ecfa608
RK
132 if (!metrics) {
133 metrics = new Dygraph(
134 document.getElementById('metrics'),
135 durations,
136 {
137 highlightCircleSize: 4,
138 labels: [ "Date", "ms" ]
139 });
140 } else {
141 metrics.updateOptions({file: durations});
142 }
62c2a51e
RK
143 var end2 = new Date();
144 document.getElementById("metaperformance").innerHTML =
145 "completed in " + (end2 - start2) + " milliseconds.";
f7adb3d7 146 }
c3fa4a74
DV
147
148 return millisecondss;
62c2a51e 149 };
a058247d 150
0a14b0f9 151 setDataType = function(radiobutton) {
a058247d
AR
152 dataType = radiobutton.value;
153 };
0a14b0f9
AV
154 setTimestampType = function(radiobutton) {
155 timestamps = radiobutton.value;
156 };
f7adb3d7 157
bbba718a
RK
158 var values = {
159 points: 100,
160 series: 1,
161 rollPeriod: 1,
162 repetitions: 1,
375adb8f 163 type: 'sine'
bbba718a
RK
164 };
165
166 // Parse the URL for parameters. Use it to override the values hash.
167 var href = window.location.href;
168 var qmindex = href.indexOf('?');
169 if (qmindex > 0) {
170 var entries = href.substr(qmindex + 1).split('&');
171 for (var idx = 0; idx < entries.length; idx++) {
172 var entry = entries[idx];
173 var eindex = entry.indexOf('=');
174 if (eindex > 0) {
175 values[entry.substr(0, eindex)] = entry.substr(eindex + 1);
176 }
177 }
178 }
179
180 var populate = function(name) {
181 document.getElementById(name).value = values[name];
182 }
183
184 var populateRadio = function(name) {
185 var val = values[name];
186 var elem = document.getElementById(val);
187 elem.checked = true;
188 elem.onclick();
189 }
190
191 populate('points');
192 populate('series');
193 populate('rollPeriod');
194 populate('repetitions');
195 populateRadio('type');
196 if (values["go"]) {
197 updatePlot();
198 }
15b00ba8
JB
199 </script>
200 </body>
201</html>