var scene = {
name: "MY SCENE"
};
var running1 = 0;
var running2 = 0;
function myClass1(name){
this.name = name;
this.getName = function(){
return this.name;
}
}
function myClass2(name){
this.name = name;
}
myClass2.prototype.getName = function(){
return this.name;
}
var MC1 = new myClass1("MICHAEL");
var MC2 = new myClass2("MICHAEL");
function method1(){
return MC1.getName();
}
function method2(){
return MC2.getName();
}
var output = document.getElementById('output');
var averages = document.getElementById('averages');
var timer = function(name) {
var start = new Date();
return {
stop: function() {
var end = new Date();
var time = end.getTime() - start.getTime();
//console.log('Timer:', name, 'finished in', time, 'ms');
output.innerHTML += 'Timer: ' + name + '<br />finished in ' + time + ' ms<br />';
},
time: function() {
var end = new Date();
return end.getTime() - start.getTime();
}
}
};
var count = 1000000;
var samples = 20;
for(var j=0;j<samples;j++){
var t = timer('toFixed Method Timer');
// code to benchmark
for(var i=0;i<count;i++){
method1();
}
//////////////////////////////////////////////////////
t.stop(); // prints the time elapsed to the js console
running1 += t.time();
var t = timer('Custom Method Timer');
// code to benchmark
for(var i=0;i<count;i++){
method2();
}
//////////////////////////////////////////////////////
t.stop(); // prints the time elapsed to the js console
running2 += t.time();
output.innerHTML += '<hr />';
}
var xFaster = parseInt(running1/samples)/parseInt((running2)/samples);
document.getElementById('xfaster').innerHTML = 'Roughly ' + xFaster.toFixed(1) + 'x Faster';
averages.innerHTML += 'PERFORMANCE 1 AVG: ' + parseInt(running1/samples) + 'ms<br />PERFORMANCE 2 AVG: ' +...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.