Initial commit
This commit is contained in:
49
framework/Measure.js
Normal file
49
framework/Measure.js
Normal file
@@ -0,0 +1,49 @@
|
||||
export default class Measure {
|
||||
|
||||
startTimes = {};
|
||||
|
||||
endTimes = {};
|
||||
|
||||
writeToPage = false;
|
||||
|
||||
element = false;
|
||||
|
||||
start ( label ) {
|
||||
|
||||
this.startTimes[ label ] = performance.now();
|
||||
}
|
||||
|
||||
end ( label ) {
|
||||
|
||||
this.endTimes[ label ] = performance.now();
|
||||
|
||||
this.log( label );
|
||||
}
|
||||
|
||||
getElapsed ( label ) {
|
||||
|
||||
if ( this.startTimes[ label ] === undefined || this.endTimes[ label ] === undefined ) {
|
||||
|
||||
throw new Error( "Start or end time missing for label: " + label );
|
||||
}
|
||||
|
||||
return this.endTimes[ label ] - this.startTimes[ label ];
|
||||
}
|
||||
|
||||
log ( label ) {
|
||||
|
||||
const elapsed = this.getElapsed( label );
|
||||
|
||||
if( this.writeToPage ) {
|
||||
|
||||
var p = document.createElement("p")
|
||||
|
||||
p.innerText = label + " took " + elapsed.toFixed(3) + " ms";
|
||||
|
||||
this.element.appendChild( p );
|
||||
|
||||
}
|
||||
|
||||
console.log( label + " took " + elapsed.toFixed(3) + " ms" );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user