Skip to content

Misc perf improvements #1772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions devtools/test_dashboard/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var credentials = require('../../build/credentials.json');
var Lib = require('@src/lib');
var d3 = Plotly.d3;

require('./perf');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @rreusser would be nice to have something like that in https://github.com/rreusser/plotly-mock-viewer

Moreover, @dfcreative's brilliant ✨ https://www.npmjs.com/package/fps-indicator ✨ would be a nice addition to our dev tools.


// Our gracious testing object
var Tabs = {

Expand Down
54 changes: 54 additions & 0 deletions devtools/test_dashboard/perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

/*
* timeit: tool for performance testing
* f: function to be tested
* n: number of timing runs
* nchunk: optional number of repetitions per timing run - useful if
* the function is very fast. Note though that if arg is a function
* it will not be re-evaluated within the chunk, only before each chunk.
* arg: optional argument to the function. Can be a function itself
* to provide a changing input to f
*/
window.timeit = function(f, n, nchunk, arg) {
var times = new Array(n);
var totalTime = 0;
var _arg;
var t0, t1, dt;

for(var i = 0; i < n; i++) {
if(typeof arg === 'function') _arg = arg();
else _arg = arg;

if(nchunk) {
t0 = performance.now();
for(var j = 0; j < nchunk; j++) { f(_arg); }
t1 = performance.now();
dt = (t1 - t0) / nchunk;
}
else {
t0 = performance.now();
f(_arg);
t1 = performance.now();
dt = t1 - t0;
}

times[i] = dt;
totalTime += dt;
}

var first = (times[0]).toFixed(4);
var last = (times[n - 1]).toFixed(4);
times.sort();
var min = (times[0]).toFixed(4);
var max = (times[n - 1]).toFixed(4);
var median = (times[Math.ceil(n / 2)]).toFixed(4);
var mean = (totalTime / n).toFixed(4);
console.log((f.name || 'function') + ' timing (ms) - min: ' + min +
' max: ' + max +
' median: ' + median +
' mean: ' + mean +
' first: ' + first +
' last: ' + last
);
};