Created
May 29, 2020 02:44
-
-
Save baoqger/3e3d793719d26f4762c753e6e5d3fc73 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
import { defaultMemoize } from "./memoizedSelector"; | |
import { slowFunction } from "./slowFunction"; | |
// run slowFunction without memoization | |
console.log("First call of slowFunction(2)"); | |
let pre = new Date(); | |
slowFunction(2); | |
console.log("It takes" + ((new Date()).valueOf() - pre.valueOf())/1000 + "seconds \n"); | |
console.log("Second call of slowFunction(2)"); | |
pre = new Date(); | |
slowFunction(2); | |
console.log("It takes" + ((new Date()).valueOf() - pre.valueOf())/1000 + "seconds \n"); | |
// run slowFunction with memoization | |
const fastFunction = defaultMemoize(slowFunction); | |
console.log("First call of fastFunction(2)"); | |
pre = new Date(); | |
fastFunction.memoized(2); | |
console.log("It takes" + ((new Date()).valueOf() - pre.valueOf())/1000 + "seconds \n"); | |
console.log("Second call of fastFunction(2)"); | |
pre = new Date(); | |
fastFunction.memoized(2); | |
console.log("It takes" + ((new Date()).valueOf() - pre.valueOf())/1000 + "seconds \n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment