Skip to content

Instantly share code, notes, and snippets.

@joshbeckman
Last active January 22, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbeckman/bfa99324875e9352aa2c719dad9743c1 to your computer and use it in GitHub Desktop.
Save joshbeckman/bfa99324875e9352aa2c719dad9743c1 to your computer and use it in GitHub Desktop.
import perf from '../lib/perf.js';
const THRESHOLD = 83; // ~ 5 animation frames
const perfMiddleware = store => next => action => {
perf.start(action.type);
let result = next(action);
perf.end(action.type);
if (perf.duration(action.type) > THRESHOLD) {
console.warn(`[perf] action ${action.type} took ${perf.duration(action.type).toFixed(2)}ms`, {
mean: perf.mean(action.type),
sdev: perf.sdev(action.type),
samples: perf.getEntriesByName(action.type).length,
});
}
return result;
};
export default perfMiddleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment