Add code to measure search function speed

This commit is contained in:
Maximilian Krög
2020-02-16 21:19:01 +01:00
parent 99ecce2a87
commit d56513b722

View File

@@ -85,11 +85,21 @@ $(function () {
const searchInput = $('#search').get(0);
// Skip searches when typing fast.
let key;
let start;
const brandNode = document.querySelector('.brand');
function queueSearch() {
if (!key) {
start = Date.now();
key = setTimeout(function () {
doSearch(searchInput.value);
key = undefined;
const searchTerm = searchInput.value;
doSearch(searchTerm);
const time = Date.now() - start
brandNode.innerHTML = time + ' ms';
console.log(searchTerm + ':', time, 'ms');
start = undefined;
}, 0);
}
}