Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show human-friendly output #2087

Merged
merged 1 commit into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions packages/adblocker-benchmarks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
const fs = require('fs');
const path = require('path');

const { _N, _T, _S } = require('./string.js');

const ENGINE = process.argv[process.argv.length - 2];
const REQUESTS_PATH = process.argv[process.argv.length - 1];

Expand Down Expand Up @@ -40,15 +42,15 @@ const WEBREQUEST_OPTIONS = {
};

function min(arr) {
let acc = Number.MAX_VALUE;
let acc = Infinity;
mjethani marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 0; i < arr.length; i += 1) {
acc = Math.min(acc, arr[i]);
}
return acc;
}

function max(arr) {
let acc = -1;
let acc = -Infinity;
for (let i = 0; i < arr.length; i += 1) {
acc = Math.max(acc, arr[i]);
}
Expand Down Expand Up @@ -183,7 +185,7 @@ async function main() {
let index = 0;
for (const request of requests) {
if (index !== 0 && index % 10000 === 0) {
console.log(`Processed ${index} requests`);
console.log(_N`Processed ${index} requests`);
}
index += 1;

Expand Down Expand Up @@ -215,36 +217,34 @@ async function main() {

console.log();
console.log(
`Avg serialization time (${serializationTimings.length} samples): ${avg(
serializationTimings,
)}`,
_N`Avg serialization time (${serializationTimings.length} samples): ` +
_T`${avg(serializationTimings)}`,
);
console.log(
`Avg deserialization time (${deserializationTimings.length} samples): ${avg(
deserializationTimings,
)}`,
_N`Avg deserialization time (${deserializationTimings.length} samples): ` +
_T`${avg(deserializationTimings)}`,
);
console.log(`Serialized size: ${cacheSize}`);
console.log(`List parsing time: ${parsingTime}`);
console.log(_S`Serialized size: ${cacheSize}`);
console.log(_T`List parsing time: ${parsingTime}`);
console.log();
console.log(`Total requests: ${all.length}`);
console.log(`Total match: ${matches.length}`);
console.log(`Total no match: ${noMatches.length}`);
console.log(_N`Total requests: ${all.length}`);
console.log(_N`Total match: ${matches.length}`);
console.log(_N`Total no match: ${noMatches.length}`);
console.log();
console.log(`Number of samples: ${matches.length}`);
console.log(`Min match: ${min(matches)}`);
console.log(`Max match: ${max(matches)}`);
console.log(`Avg match: ${avg(matches)}`);
console.log(_N`Number of samples: ${matches.length}`);
console.log(_T`Min match: ${min(matches)}`);
console.log(_T`Max match: ${max(matches)}`);
console.log(_T`Avg match: ${avg(matches)}`);
console.log();
console.log(`Number of samples: ${noMatches.length}`);
console.log(`Min no match: ${min(noMatches)}`);
console.log(`Max no match: ${max(noMatches)}`);
console.log(`Avg no match: ${avg(noMatches)}`);
console.log(_N`Number of samples: ${noMatches.length}`);
console.log(_T`Min no match: ${min(noMatches)}`);
console.log(_T`Max no match: ${max(noMatches)}`);
console.log(_T`Avg no match: ${avg(noMatches)}`);
console.log();
console.log(`Number of samples: ${all.length}`);
console.log(`Min (total): ${min(all)}`);
console.log(`Max (total): ${max(all)}`);
console.log(`Avg (total): ${avg(all)}`);
console.log(_N`Number of samples: ${all.length}`);
console.log(_T`Min (total): ${min(all)}`);
console.log(_T`Max (total): ${max(all)}`);
console.log(_T`Avg (total): ${avg(all)}`);

fs.writeFileSync(`./data/${ENGINE}_timings.json`, JSON.stringify(stats), { encoding: 'utf-8' });
}
Expand Down
27 changes: 27 additions & 0 deletions packages/adblocker-benchmarks/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*!
* Copyright (c) 2017-present Cliqz GmbH. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

const _N = (strings, number) => strings[0] + number.toLocaleString() + strings[1];

module.exports = {
_N,

_T: (strings, time) => {
if (time === Infinity || time === -Infinity) {
time = NaN;
}

const formatted = isNaN(time) ? 'n/a' : _N`${Math.round(time * 1e6) / 1e3} μs`;
mjethani marked this conversation as resolved.
Show resolved Hide resolved
return strings[0] + formatted + strings[1];
},

_S: (strings, size) => {
const formatted = size === null ? 'n/a' : _N`${Math.ceil(size / 1024)} KiB`;
return strings[0] + formatted + strings[1];
},
};