var Benchmark = function() { }; Benchmark.prototype.start = function() { this.start = new Date().getTime(); console.time('Benchmark'); }; Benchmark.prototype.stop = function() { this.stop = new Date().getTime(); console.timeEnd('Benchmark'); }; Benchmark.prototype.read = function() { this.data = localStorage.getItem('benchy'); if(this.data) { this.data = JSON.parse(this.data); } else { this.data = []; } }; Benchmark.prototype.write = function() { this.read(); this.data.push(this.stop - this.start); localStorage.setItem('benchy', JSON.stringify(this.data)); }; Benchmark.prototype.stats = function() { this.read(); console.log(typeof this.data); var avg = this.data.reduce(function(prev, curr, index, arr) { if(index === arr.length-1) { return (prev + curr) / arr.length; } return prev + curr; }, 0); console.log('avg: ' + avg + 'ms'); console.log(this.data); }; Benchmark.prototype.reset = function() { localStorage.setItem('benchy', '[]'); }; Benchmark.prototype.repeat = function(times) { this.read(); if(this.data.length < times) { window.location.reload(); } else { this.reset(); } }; window.benchy = new Benchmark();