Created
April 12, 2022 20:37
-
-
Save guligon90/ef0673da0e1c0414fe6cbf77aa3da455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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