Skip to content

Instantly share code, notes, and snippets.

@addyosmani
Forked from ebidel/polymer-perf-bookmarklet.js
Last active September 8, 2015 16:04
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 addyosmani/d437f9679269f946b4d8 to your computer and use it in GitHub Desktop.
Save addyosmani/d437f9679269f946b4d8 to your computer and use it in GitHub Desktop.
Polymer performance numbers bookmarklet
javascript:(function(){(function printStats(){var loadTimes=window.chrome.loadTimes();firstPaint=loadTimes.firstPaintTime*1000;firstPaintTime=firstPaint-(loadTimes.startLoadTime*1000);console.info('First paint took',firstPaintTime,'ms');console.info('Load took',performance.timing.loadEventStart-performance.timing.navigationStart,'ms');var instances=0;if(parseFloat(Polymer.version)<1){instances=[].slice.call(document.querySelectorAll('html /deep/ *')).filter(function(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}).length;}else{instances=Polymer.telemetry.instanceCount;}console.info('Custom element instances:',instances);var reflectCount=0;if(Polymer.telemetry){console.info('=== Properties set to reflectToAttribute ===');Polymer.telemetry.registrations.forEach(function(el){for(var prop in el.properties){if(el.properties[prop].reflectToAttribute){console.log(el.is+'.'+prop);reflectCount++;}}});}else{console.info('=== Properties set to reflect ===');Polymer.elements.forEach(function(el){for(var prop in el.prototype.publish){var propVal=el.prototype.publish[prop];if(propVal&&propVal.reflect){console.log(el.name+'.'+prop);reflectCount++;}}});}console.info('Total properties set to reflectToAttribute:',reflectCount);var imports=document.querySelectorAll('link[rel="import"]');var table=[];var totalDuration=0;console.info('=== HTML Imports load times ===');[].forEach.call(imports,function(link){var entries=performance.getEntriesByName(link.href);entries.forEach(function(e){table.push({url:e.name,ms:e.duration});totalDuration+=e.duration;});});console.log(imports.length+' imports loaded from the main page. Total time: '+totalDuration+'ms');console.table(table);})();})();
(function printStats() {
// First paint
var loadTimes = window.chrome.loadTimes();
firstPaint = loadTimes.firstPaintTime * 1000;
firstPaintTime = firstPaint - (loadTimes.startLoadTime * 1000);
console.info('First paint took', firstPaintTime, 'ms');
// Page load.
console.info('Load took', performance.timing.loadEventStart - performance.timing.navigationStart, 'ms');
// # of custom element instances
var instances = 0;
if (parseFloat(Polymer.version) < 1) { // Polymer 0.5.
instances = [].slice.call(document.querySelectorAll('html /deep/ *')).filter(function(el) {
return el.localName.indexOf('-') != -1 || el.getAttribute('is');
}).length;
} else {
instances = Polymer.telemetry.instanceCount;
}
console.info('Custom element instances:', instances);
// Properties being reflected to attributes.
var reflectCount = 0;
if (Polymer.telemetry) {
console.info('=== Properties set to reflectToAttribute ===');
Polymer.telemetry.registrations.forEach(function(el) {
for (var prop in el.properties) {
if (el.properties[prop].reflectToAttribute) {
console.log(el.is + '.' + prop);
reflectCount++;
}
}
});
} else { // 0.5 code
console.info('=== Properties set to reflect ===');
Polymer.elements.forEach(function(el) {
for (var prop in el.prototype.publish) {
var propVal = el.prototype.publish[prop];
if (propVal && propVal.reflect) {
console.log(el.name + '.' + prop);
reflectCount++;
}
}
});
}
console.info('Total properties set to reflectToAttribute:', reflectCount);
// Main page imports perf.
var imports = document.querySelectorAll('link[rel="import"]');
var table = [];
var totalDuration = 0;
console.info('=== HTML Imports load times ===');
[].forEach.call(imports, function(link) {
var entries = performance.getEntriesByName(link.href);
entries.forEach(function(e) {
table.push({url: e.name, ms: e.duration});
totalDuration += e.duration;
});
});
console.log(imports.length + ' imports loaded from the main page. Total time: ' + totalDuration + 'ms');
console.table(table);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment