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();
document.writeln('---Using Try/Catch, Trial ' + (i + 1) + '---<br />');
document.writeln('started : ' + t1 + '<br />');
this.goTry(t1);
this.countWith++;
}
for (i = 0; i < 5; i++) {
t1 = this.getTime();
document.writeln('---W/out Try/Catch, Trial ' + (i + 1) + '---<br />');
document.writeln('started : ' + t1 + '<br />');
this.goAlone(t1);
this.countWithout++;
}
for (i = 5; i < 10; i++) {
t1 = this.getTime();
document.writeln('---Using Try/Catch, Trial ' + (i + 1) + '---<br />');
document.writeln('started : ' + t1 + '<br />');
this.goTry(t1);
this.countWith++;
}
for (i = 5; i < 10; i++) {
t1 = this.getTime();
document.writeln('---W/out Try/Catch, Trial ' + (i + 1) + '---<br />');
document.writeln('started : ' + t1 + '<br />');
this.goAlone(t1);
this.countWithout++;
}
document.writeln('---------------------------------------<br />');
document.writeln('Average time (ms) USING Try/Catch: ' + this.sumWith / this.countWith + ' ms<br />');
document.writeln('Average time (ms) W/OUT Try/Catch: ' + this.sumWithout / this.countWithout + ' ms<br />');
document.writeln('---------------------------------------<br />');
},
getTime: function() {
return new Date();
},
done: function(t1, wasTry) {
var t2 = this.getTime();
var td = t2 - t1;
document.writeln('ended.....: ' + t2 + '<br />');
...