Improve benchmarking.

This commit is contained in:
kor 2018-11-07 00:12:54 +13:00
parent 2d08df6079
commit 03b9e3f777
5 changed files with 68 additions and 53 deletions

View File

@ -17,10 +17,10 @@
<!-- everything above here is for initial load (aka: display bg and pretty loading anim ASAP!) -->
<script src="logic/mark.js"></script>
<script src="logic/seer.js"></script>
<script>
var benchmark = new Mark();
benchmark.install();
var seer = new Seer();
seer.install(false, 1);
</script>
<div class="error"></div>

View File

@ -14,7 +14,7 @@ function Main()
this.install = function()
{
benchmark.note('load all js files');
seer.note('load all js files');
this.util = new Util();
this.database = new Wrap();
@ -39,7 +39,7 @@ function Main()
// }
}
benchmark.note('install main');
seer.note('install main');
}
this.resetPage = function()
@ -67,31 +67,31 @@ function Main()
{
this.database.start()
.then((db) => {
benchmark.note('process db');
seer.note('process db');
this.resetPage();
this.updateQuery();
benchmark.note('prep query');
seer.note('prep query');
return this.database.filter(db, this.queryCur);
})
.then((filtered) => {
benchmark.note('filter db');
seer.note('filter db');
return this.grid.buildAllArticles(filtered);
})
.then((html) => {
benchmark.note('build html');
seer.note('build html');
let stats = this.database.stats();
benchmark.note('calc stats');
seer.note('calc stats');
this.nav.display(stats);
benchmark.note('render stats');
seer.note('render stats');
this.grid.newDisplay(html);
// benchmark.note('render html');
// seer.note('render html');
benchmark.complete();
seer.report();
document.querySelector('.loading-wave').style.display = 'none';
})
@ -102,6 +102,11 @@ function Main()
//
}
this.load = function()
{
}
// this.load = function(target)
// {
// lightbox.close();

View File

@ -1,38 +0,0 @@
function Mark()
{
this.timeBegin = null;
this.timeStore = null;
this.curTime = null;
this.specialDesc = null;
this.specialTime = null;
this.install = function()
{
this.timeBegin = Date.now();
this.timeStore = Date.now();
}
this.note = function(desc)
{
this.curTime = Date.now();
console.log((this.curTime - this.timeStore) + ' ms to ' + desc);
this.timeStore = this.curTime;
}
this.special = function(desc)
{
this.specialDesc = desc;
this.specialTime = Date.now() - this.timeStore;
this.note(desc);
}
this.complete = function()
{
let total = (Date.now() - this.timeBegin);
console.log('TOTAL TIME: ' + total + ' ms');
if (this.specialDesc != null)
{
console.log(((this.specialTime / total)*100).toFixed(0) + ' % of time spent on: ' + this.specialDesc);
}
}
}

48
docs/logic/seer.js Normal file
View File

@ -0,0 +1,48 @@
"use strict";
function Seer()
{
this.verbose = false
this.quota = 0;
this.timeBegin = null;
this.timeRef = null;
this.book = null;
this.install = function(verbose, quota)
{
this.verbose = verbose;
this.quota = quota;
this.timeBegin = Date.now();
this.timeRef = Date.now();
this.book = [];
}
this.note = function(desc)
{
var entry = [desc, (Date.now() - this.timeRef)];
this.book.push(entry);
if (this.verbose)
{
console.log(entry[1] + ' ms to ' + entry[0]);
}
this.timeRef = Date.now();
}
this.report = function()
{
let total = (Date.now() - this.timeBegin);
console.log('Completed in: ' + total + ' ms');
if (this.quota > 0)
{
this.book.sort(function(a, b)
{
return a[1] + b[1];
});
for (var i = 0; i < Math.min(this.quota, this.book.length); i++)
{
let percentage = ((this.book[i][1] / total) * 100).toFixed(1);
console.log(percentage + ' % of time spent on: ' + this.book[i][0]);
}
}
}
}

View File

@ -33,7 +33,7 @@ function Grid()
document.querySelector('main').innerHTML = html;
benchmark.note('render html');
seer.note('render html');
// LAYOUT
if (SETTINGS.USEMASONRY)
@ -56,7 +56,7 @@ function Grid()
}
}
benchmark.special('masonry layout');
seer.note('masonry layout');
}
}