Skip to content

Instantly share code, notes, and snippets.

@guligon90
Created April 12, 2022 20:37
Show Gist options
  • Save guligon90/ef0673da0e1c0414fe6cbf77aa3da455 to your computer and use it in GitHub Desktop.
Save guligon90/ef0673da0e1c0414fe6cbf77aa3da455 to your computer and use it in GitHub Desktop.
const problemSize = 10000;
const g = n => n ** 2; // theoretical guess function
const timeRatios = [];
const m = 5; // from the O(g(n)) definition
const alpha = 1/127.372 // some suitable conversion constant
// depending on the CPUs number of
// instructions per second
let start = 0;
for (const n = m; i <= problemSize; n++) {
try {
start = performance.now();
performanceSensitiveAlgorithm(n); // The code being analyzed
} catch (error) {
// Some appropriate error handling here...
} finally {
const measuredTime = performance.now() - start; // in ms
const theoreticalTime = alpha * g(n) // now in ms
timeRatios.push(theoreticalTime/measuredTime); // dimensionless
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment