4 <meta http-equiv=
"X-UA-Compatible" content=
"IE=EmulateIE7; IE=EmulateIE9">
5 <title>Benchmarking for Plots with Many Points
</title>
7 <script type=
"text/javascript" src=
"../excanvas.js"></script>
10 For production (minified) code, use:
11 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
13 <script type=
"text/javascript" src=
"../dygraph-dev.js"></script>
17 <p>Plot which can be easily generated with different numbers of points for
18 benchmarking/profiling and improving performance of dygraphs.
</p>
21 <input type=
"radio" id=
"sine" name=
"group1" value=
"sine"
22 onclick=
"setDataType(this);" checked
> sinusoid function
23 <input type=
"radio" id=
"rand" name=
"group1" value=
"rand"
24 onclick=
"setDataType(this);"> random points
<br></p>
26 <input type=
"radio" id=
"aligned" name=
"timestamps" value=
"aligned"
27 onclick=
"setTimestampType(this);" checked
> aligned
28 <input type=
"radio" id=
"unaligned" name=
"timestamps" value=
"unaligned"
29 onclick=
"setTimestampType(this);"> unaligned
</p>
30 <p>Number of points per series (points):
31 <input type=
"text" id=
"points" size=
"20"></p>
32 <p>Number of series (series):
33 <input type=
"text" id=
"series" size=
"20"></p>
34 <p>Roll period (in points, rollPeriod):
35 <input type=
"text" id=
"rollPeriod" size=
"20"></p>
36 <p>Repetitions (repititions):
37 <input type=
"text" id=
"repetitions" size=
"20"></p>
38 <input type=
"button" value=
"Go!" onclick=
"updatePlot();">
43 <div id=
"message"></div>
44 <div id=
"metrics"></div>
45 <div id=
"metaperformance"></div>
47 <script type=
"text/javascript">
50 var dataType =
"sine";
51 var timestamps =
"aligned";
54 updatePlot = function() {
55 document.getElementById('message').innerHTML =
"";
56 var plotDiv = document.getElementById('plot');
57 plotDiv.innerHTML = 'Redrawing...';
59 parseInt(document.getElementById('points').value);
61 parseInt(document.getElementById('series').value);
63 parseInt(document.getElementById('repetitions').value);
67 var xmax =
2.0 * Math.PI;
69 var delta = (xmax - xmin) / (numPoints -
1);
70 var unalignmentDelta = delta / numSeries;
72 for (var i =
0; i < numPoints; ++i) {
73 var x = xmin + delta * i;
75 for (var j =
0; j < numSeries; j++) {
77 if (dataType ==
"rand") {
78 y = Math.pow(Math.random() - Math.random(),
7);
80 y = Math.sin(x + (j * adj));
84 if (timestamps ==
"aligned") {
87 for (var j =
0; j < numSeries; j++) {
88 var elemCopy = elem.slice(
0);
89 elemCopy[
0] += unalignmentDelta * j;
90 data[i*numSeries + j] = elemCopy;
95 for (var j =
0; j < numSeries; j++) {
96 labels.push(
"data-set-" + j);
98 var rollPeriod = parseInt(
99 document.getElementById('rollPeriod').value);
100 var opts = {labels: labels, rollPeriod: rollPeriod, timingName:
"x"};
101 var millisecondss = [];
102 for (var i =
0; i < repetitions; i++) {
104 graph.destroy(); // release memory from prior graph.
106 var start = new Date();
107 graph = new Dygraph(plotDiv, data, opts);
108 var end = new Date();
109 durations.push([start, end - start]);
110 millisecondss.push(end - start);
112 if (repetitions ==
1) {
113 document.getElementById('message').innerHTML =
114 "completed in " + (end - start) +
" milliseconds.";
117 for (var i =
0; i < millisecondss.length; i++) {
118 avg+=millisecondss[i];
120 avg/=millisecondss.length;
121 document.getElementById('message').innerHTML =
122 "Durations: " + millisecondss +
" Average: " + avg;
125 if (durations.length
> 0) {
126 var start2 = new Date();
128 metrics = new Dygraph(
129 document.getElementById('metrics'),
132 highlightCircleSize:
4,
133 labels: [
"Date",
"ms" ]
136 metrics.updateOptions({file: durations});
138 var end2 = new Date();
139 document.getElementById(
"metaperformance").innerHTML =
140 "completed in " + (end2 - start2) +
" milliseconds.";
143 return millisecondss;
146 setDataType = function(radiobutton) {
147 dataType = radiobutton.value;
149 setTimestampType = function(radiobutton) {
150 timestamps = radiobutton.value;
161 // Parse the URL for parameters. Use it to override the values hash.
162 var href = window.location.href;
163 var qmindex = href.indexOf('?');
165 var entries = href.substr(qmindex +
1).split('&');
166 for (var idx =
0; idx < entries.length; idx++) {
167 var entry = entries[idx];
168 var eindex = entry.indexOf('=');
170 values[entry.substr(
0, eindex)] = entry.substr(eindex +
1);
175 var populate = function(name) {
176 document.getElementById(name).value = values[name];
179 var populateRadio = function(name) {
180 var val = values[name];
181 var elem = document.getElementById(val);
188 populate('rollPeriod');
189 populate('repetitions');
190 populateRadio('type');