JSFiddle - React, Tailwind, and code Playground

by Michael Prosser

JavaScript

var scene = {
	name: "MY SCENE"
};

function method1(age){

	this.age = age;
  
  this.getAge = function(){
  
  	return this.age;
  
  }

}

function method2(age){

	return {
    getAge: function() {
      return age;
    }
  }

}

function test1(s){

	var n = s.name;

}

function test2(){

	var n = scene.name;

}

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');
        }
    }
};

var count = 100000000;

var t = timer('AS INSTANCE');
// code to benchmark

for(var i=0;i<count;i++){

	//test1(scene);
  method1(25);

}

//////////////////////////////////////////////////////
t.stop(); // prints the time elapsed to the js console



var t = timer('AS RETURNED');
// code to benchmark

for(var i=0;i<count;i++){

	//test2();
  method2(25);

}

//////////////////////////////////////////////////////
t.stop(); // prints the time elapsed to the js console