JSFiddle - React, Tailwind, and code Playground
by b_long
JavaScript
var Speedy = function() {
this.init();
};
Speedy.prototype = {
init: function() {
var i, t1;
this.sumWith = 0;
this.sumWithout = 0;
this.countWith = 0;
this.countWithout = 0;
for (i = 0; i < 5; i++) {
t1 = this.getTime();
console.log("Using Try/Catch, Trial #" + (i + 1) );
console.log("started " + t1 );
this.goTry(t1);
this.countWith++;
}
for (i = 0; i < 5; i++) {
t1 = this.getTime();
console.log("W/out Try/Catch, Trial #" + (i + 1) );
console.log("started :" + t1 );
this.goAlone(t1);
this.countWithout++;
}
for (i = 5; i < 10; i++) {
t1 = this.getTime();
console.log("Using Try/Catch, Trial #" + (i + 1) );
console.log("started :" + t1);
this.goTry(t1);
this.countWith++;
}
for (i = 5; i < 10; i++) {
t1 = this.getTime();
console.log("W/out Try/Catch, Trial #" + (i + 1) );
console.log("started :" + t1);
this.goAlone(t1);
this.countWithout++;
}
console.log("---------------------------------------");
console.log("Average time (ms) USING Try/Catch: " + this.sumWith / this.countWith + " ms");
console.log("Average time (ms) W/OUT Try/Catch: " + this.sumWithout / this.countWithout + " ms");
console.log("---------------------------------------");
},
getTime: function() {
return new Date();
},
done: function(t1, wasTry) {
var t2 = this.getTime();
var td = t2 - t1;
console.log("ended.....: " + t2);
console.log("diff......: " + td);
if (wasTry) {
this.sumWith += td;
}
else {
this.sumWithout += td;
}
},
goTry: function(t1) {
try {
var counter =...