[plt-scheme] Unexpected slowdown using memoized function

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Aug 12 07:35:26 EDT 2007

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



Posted on the users mailing list.