Add memoization and run some quick tests on its performance.