Last active
January 22, 2018 23:29
-
-
Save joshbeckman/bfa99324875e9352aa2c719dad9743c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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