Last active
February 15, 2026 11:40
-
-
Save espio999/c0b35d76b0f762b7e59f0d39adb6d812 to your computer and use it in GitHub Desktop.
test for memoization
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
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <script src="fibonacci.js"></script> | |
| <script> | |
| function measurePerformance(label, func){ | |
| const point_start = `${label} ----- start`; | |
| const point_finish = `${label} ----- end`; | |
| performance.mark(point_start); | |
| console.log(func(n)); | |
| performance.mark(point_finish); | |
| const duration = performance.measure(label, point_start, point_finish).duration; | |
| console.log(duration); | |
| } | |
| function concat(...args){ | |
| let ret = ""; | |
| for (let arg of args){ | |
| ret = ret + arg.toString(); | |
| } | |
| return ret; | |
| } | |
| const n = 40; | |
| const fib_memo = memoization(fibonacci); | |
| let i = 0; | |
| while(i < 3){ | |
| measurePerformance(i, fib_memo); | |
| i++; | |
| } | |
| const concat_memo = memoization(concat); | |
| console.log(concat_memo()); | |
| console.log(concat_memo(1)); | |
| console.log(concat_memo(1, 2)); | |
| console.log(concat_memo(1, 2, 3)); | |
| console.log(concat_memo('a', 'b', 'c')); | |
| console.log(concat_memo([0, 1], 'b')); | |
| console.log(concat_memo([0, 1], 'b')); //Cache hitのコンソール出力あり→メモ出力 | |
| </script> | |
| </head> | |
| <body></body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment