Last active
May 13, 2021 08:04
-
-
Save A1rPun/653dbd9e9227a92747cc99390b2c8864 to your computer and use it in GitHub Desktop.
Generic helper stuff for experiments
This file contains hidden or 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
function memoizer(fn) { | |
const cache = new Map([]); | |
return (...args) => { | |
let result; | |
const key = args.toString(); | |
if (cache.has(key)) | |
result = cache.get(key); | |
else { | |
result = fn(...args); | |
cache.set(key, result); | |
} | |
return result; | |
}; | |
} | |
function perfTime(fn) { | |
return (...args) => { | |
const begin = performance.now(); | |
const result = fn(...args); | |
const end = performance.now(); | |
console.log(`Code execution took ${end - begin} milliseconds.`); | |
return result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment