Skip to content

Instantly share code, notes, and snippets.

@kemsky
Created March 1, 2017 13:14
Show Gist options
  • Save kemsky/7fbb9fc33113ce66779c1dc511e5d136 to your computer and use it in GitHub Desktop.
Save kemsky/7fbb9fc33113ce66779c1dc511e5d136 to your computer and use it in GitHub Desktop.
Measure and report Angular 2 change detection time
const detectChanges = changeDetector['_view']['detectChanges'];
let detect = 0;
let title = document.getElementsByTagName('title')[0] as HTMLTitleElement;
changeDetector['_view']['detectChanges'] = () => {
detect++;
const start = getTimer();
detectChanges.apply(changeDetector['_view']);
let time = (getTimer() - start);
let text = ` [${detect}] ${time.toFixed(2)} ms`;
title.text = text;
if(time > 25)
{
console.warn(text);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment