var charAry = (()=>{
var i = 0;
var chars = [];
while (i <= 25) {
chars.push(String.fromCharCode(65 + i));
i++;
}
return chars;
})();
リソースの取得時間計測
(()=>{
// https://www.w3.org/TR/2016/WD-resource-timing-20160225/#processing-model
var resources: Array<PerformanceResourceTiming> = performance.getEntriesByType("resource");
resources.forEach((res: PerformanceResourceTiming, index: number) => {
console.log(res.name, res.responseEnd - res.startTime);
});
})();
(()=>{
//http://w3c.github.io/navigation-timing/#processing-model
let pef: Object = {
redirect: (): number => performance.timing.redirectEnd - performance.timing.redirectStart,
unload: (): number => performance.timing.unloadEventEnd - performance.timing.unloadEventStart,
appCache: (): number => performance.timing.domainLookupStart - performance.timing.fetchStart,
DNS: (): number => performance.timing.domainLookupEnd - performance.timing.domainLookupStart,
TCP: (): number => performance.timing.connectEnd - performance.timing.connectStart,
Request: (): number => performance.timing.redirectEnd - performance.timing.redirectStart,
Processing: (): number => performance.timing.loadEventStart - performance.timing.responseEnd,
DOMContentLoaded: (): number => performance.timing.domContentLoadedEventEnd - performance.timing.domContentLoadedEventStart,
Load: (): number => performance.timing.loadEventEnd - performance.timing.loadEventStart,
}
let lineRender = (_glaph: d3.Selection<any>, timing: string ,col: number, width: number) => {
_glaph.append('text').attr("x", 1).attr("y", (12 * col) - 2).attr('font-size', '9px').text(`${timing}(${width})`);
_glaph.append('line').attr('stroke-width', 2).attr('stroke', 'red')
.attr('x1', 1).attr('x2', width + 1)
.attr('y1', 12 * col).attr('y2', 12 * col)
}
let glaph = d3.select('body').append('svg');
glaph.attr('width', 500);
glaph.attr('height', 300);
var idx = 1;
for (var fnc in pef) {
console.log(fnc, (<any>pef)[fnc]());
lineRender(glaph, fnc, idx++, (<any>pef)[fnc]())
}
})();