Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Fix missing window.perfTiming and correct line-endings
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Sep 5, 2017
1 parent e1c45f3 commit 34d401c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
135 changes: 69 additions & 66 deletions perf.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http:polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http:polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http:polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http:polymer.github.io/PATENTS.txt
*/
// x-browser compat.
(function() {
let wcr = false;

addEventListener('WebComponentsReady', function() {
wcr = true;
});

console.perf = function() {
if (window.HTMLImports && !HTMLImports.useNative && !wcr) {
let fn = console._perf.bind(console);
HTMLImports.whenReady(fn);
} else {
console._perf();
}
};

console._perf = function() {
if (window.gc) {
for (let i=0; i<20; i++) {
gc();
}
}
if (console.time) {
console.time('perf');
}
console.perf.time = performance.now();
};

console.perfEnd = function(info) {
if (window.WebComponents) {
if (!wcr) {
addEventListener('WebComponentsReady', function() {
console._perfEnd(info);
});
} else {
console._perfEnd(info);
}
} else {
console._perfEnd(info);
}
};

console._perfEnd = function(info) {
// force layout
document.body.offsetWidth;
let time = performance.now() - console.perf.time;
if (console.time) {
console.timeEnd('perf');
}
document.title = time.toFixed(1) + 'ms: ' + document.title;
if (window.top !== window) {
window.top.postMessage({time: time + 'ms', info: info}, '*');
}
};

})();
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http:polymer.github.io/LICENSE.txt The complete set of authors may be found
* at http:polymer.github.io/AUTHORS.txt The complete set of contributors may be
* found at http:polymer.github.io/CONTRIBUTORS.txt Code distributed by Google
* as part of the polymer project is also subject to an additional IP rights
* grant found at http:polymer.github.io/PATENTS.txt
*/
// x-browser compat.
(function() {
let wcr = false;

addEventListener('WebComponentsReady', function() {
wcr = true;
});

console.perf = function() {
if (window.HTMLImports && !HTMLImports.useNative && !wcr) {
let fn = console._perf.bind(console);
HTMLImports.whenReady(fn);
} else {
console._perf();
}
};

console._perf = function() {
if (window.gc) {
for (let i = 0; i < 20; i++) {
gc();
}
}
if (console.time) {
console.time('perf');
}
console.perf.time = performance.now();
};

console.perfEnd = function(info) {
if (window.WebComponents) {
if (!wcr) {
addEventListener('WebComponentsReady', function() {
console._perfEnd(info);
});
} else {
console._perfEnd(info);
}
} else {
console._perfEnd(info);
}
};

console._perfEnd = function(info, options = {}) {
if (!options.skipForceLayout) {
// force layout
document.body.offsetWidth;
}
window.perfTiming = performance.now() - console.perf.time;
if (console.time) {
console.timeEnd('perf');
}
document.title = window.perfTiming.toFixed(1) + 'ms: ' + document.title;
if (window.top !== window) {
window.top.postMessage({time: window.perfTiming + 'ms', info}, '*');
}
};

})();

0 comments on commit 34d401c

Please sign in to comment.