-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to benchmarking debug logs. debug now logs total passthr…
…ough copy file weight.
- Loading branch information
Showing
8 changed files
with
63 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
export default function (callback) { | ||
export default function (callback, options = {}) { | ||
let { bench, name } = options; | ||
let cache = new Map(); | ||
|
||
return (...args) => { | ||
// Only supports single-arg functions for now. | ||
if (args.filter(Boolean).length > 1) { | ||
bench?.get(`(count) ${name} Not valid for memoize`).incrementCount(); | ||
return callback(...args); | ||
} | ||
|
||
let [cacheKey] = args; | ||
|
||
if (!cache.has(cacheKey)) { | ||
cache.set(cacheKey, callback(...args)); | ||
|
||
bench?.get(`(count) ${name} memoize miss`).incrementCount(); | ||
|
||
return cache.get(cacheKey); | ||
} | ||
|
||
bench?.get(`(count) ${name} memoize hit`).incrementCount(); | ||
|
||
return cache.get(cacheKey); | ||
}; | ||
} |
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