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
  • Select an option

  • Save addyosmani/d437f9679269f946b4d8 to your computer and use it in GitHub Desktop.

Select an option

Save addyosmani/d437f9679269f946b4d8 to your computer and use it in GitHub Desktop.

Revisions

  1. @ebidel ebidel revised this gist Sep 4, 2015. 2 changed files with 9 additions and 4 deletions.
    2 changes: 1 addition & 1 deletion polymer-perf-bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    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"]');[].forEach.call(imports,function(link){var entries=performance.getEntriesByName(link.href);console.info('=== HTML Imports perf ===');entries.forEach(function(e){console.info(e.name,'took',e.duration,'ms');});});})();})();
    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);})();})();
    11 changes: 8 additions & 3 deletions polymer-perf.js
    Original file line number Diff line number Diff line change
    @@ -43,16 +43,21 @@
    }
    });
    }
    console.info('Total properties set to reflectToAttribute', 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);
    console.info('=== HTML Imports perf ===');
    entries.forEach(function(e) {
    console.info(e.name, 'took', e.duration, 'ms');
    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);

    })();
  2. @ebidel ebidel renamed this gist Sep 1, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @ebidel ebidel renamed this gist Sep 1, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @ebidel ebidel renamed this gist Sep 1, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @ebidel ebidel created this gist Sep 1, 2015.
    1 change: 1 addition & 0 deletions bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    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"]');[].forEach.call(imports,function(link){var entries=performance.getEntriesByName(link.href);console.info('=== HTML Imports perf ===');entries.forEach(function(e){console.info(e.name,'took',e.duration,'ms');});});})();})();
    58 changes: 58 additions & 0 deletions polymer-perf.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    (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"]');
    [].forEach.call(imports, function(link) {
    var entries = performance.getEntriesByName(link.href);
    console.info('=== HTML Imports perf ===');
    entries.forEach(function(e) {
    console.info(e.name, 'took', e.duration, 'ms');
    });
    });

    })();