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=
"clickedRadioButton(this);" checked
> sinusoid function
23 <input type=
"radio" id=
"rand" name=
"group1" value=
"rand"
24 onclick=
"clickedRadioButton(this);"> random points
<br></p>
26 <input type=
"text" id=
"points" size=
"20"></p>
28 <input type=
"text" id=
"series" size=
"20"></p>
29 <p>Roll period (in points):
30 <input type=
"text" id=
"rollPeriod" size=
"20"></p>
32 <input type=
"text" id=
"repetitions" size=
"20"></p>
33 <input type=
"button" value=
"Go!" onclick=
"updatePlot();">
38 <div id=
"message"></div>
39 <div id=
"metrics"></div>
40 <div id=
"metaperformance"></div>
42 <script type=
"text/javascript">
45 var dataType =
"sine";
48 updatePlot = function() {
49 document.getElementById('message').innerHTML =
"";
50 var plotDiv = document.getElementById('plot');
51 plotDiv.innerHTML = 'Redrawing...';
53 parseInt(document.getElementById('points').value);
55 parseInt(document.getElementById('series').value);
57 parseInt(document.getElementById('repetitions').value);
61 var xmax =
2.0 * Math.PI;
63 var delta = (xmax - xmin) / (numPoints -
1);
65 for (var i =
0; i < numPoints; ++i) {
66 var x = xmin + delta * i;
68 for (var j =
0; j < numSeries; j++) {
70 if (dataType ==
"rand") {
71 y = Math.pow(Math.random() - Math.random(),
7);
73 y = Math.sin(x + (j * adj));
80 for (var j =
0; j < numSeries; j++) {
81 labels.push(
"data-set-" + j);
83 var rollPeriod = parseInt(
84 document.getElementById('rollPeriod').value);
85 var opts = {labels: labels, rollPeriod: rollPeriod, timingName:
"x"};
86 var millisecondss = [];
87 for (var i =
0; i < repetitions; i++) {
89 graph.destroy(); // release memory from prior graph.
91 var start = new Date();
92 graph = new Dygraph(plotDiv, data, opts);
94 durations.push([start, end - start]);
95 millisecondss.push(end - start);
97 if (repetitions ==
1) {
98 document.getElementById('message').innerHTML =
99 "completed in " + (end - start) +
" milliseconds.";
102 for (var i =
0; i < millisecondss.length; i++) {
103 avg+=millisecondss[i];
105 avg/=millisecondss.length;
106 document.getElementById('message').innerHTML =
107 "Durations: " + millisecondss +
" Average: " + avg;
110 if (durations.length
> 0) {
111 var start2 = new Date();
113 metrics = new Dygraph(
114 document.getElementById('metrics'),
117 highlightCircleSize:
4,
118 labels: [
"Date",
"ms" ]
121 metrics.updateOptions({file: durations});
123 var end2 = new Date();
124 document.getElementById(
"metaperformance").innerHTML =
125 "completed in " + (end2 - start2) +
" milliseconds.";
129 clickedRadioButton = function(radiobutton) {
130 dataType = radiobutton.value;
141 // Parse the URL for parameters. Use it to override the values hash.
142 var href = window.location.href;
143 var qmindex = href.indexOf('?');
145 var entries = href.substr(qmindex +
1).split('&');
146 for (var idx =
0; idx < entries.length; idx++) {
147 var entry = entries[idx];
148 var eindex = entry.indexOf('=');
150 values[entry.substr(
0, eindex)] = entry.substr(eindex +
1);
155 var populate = function(name) {
156 document.getElementById(name).value = values[name];
159 var populateRadio = function(name) {
160 var val = values[name];
161 var elem = document.getElementById(val);
168 populate('rollPeriod');
169 populate('repetitions');
170 populateRadio('type');