Skip to content

Instantly share code, notes, and snippets.

@A1rPun
Last active May 13, 2021 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A1rPun/653dbd9e9227a92747cc99390b2c8864 to your computer and use it in GitHub Desktop.
Save A1rPun/653dbd9e9227a92747cc99390b2c8864 to your computer and use it in GitHub Desktop.
Generic helper stuff for experiments
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