[plt-scheme] Unexpected slowdown using memoized function
Jos Koot wrote:
> The prime? predicate of math.ss precomputes and memoizes the primeness
> of all natural numbers <= 1000000.
> Adding an extra layer of memoization necessarily slows down, ...
That's spot on.
>> (require (planet "math.ss" ("soegaard" "math.plt" 1 0)))
Version 1.2 was released a few days ago (and as opposes to 1.1 actually
works).
>> (define/memo (P x)
>> (prime? (bit-count x))))
If there is a possibility that x is a bignum, remember to use
define/memo* .
--
Jens Axel Søgaard