[plt-scheme] Science Collection

From: Williams, M. Douglas (M.DOUGLAS.WILLIAMS at saic.com)
Date: Mon Oct 4 10:04:30 EDT 2004

Unfortunately, that describes almost all of my examples - and often the
intended use.  A typical example is:

(require (lib "gaussian.ss" "science" "random-distributions"))
(require (lib "histogram-with-graphics.ss" "science"))

(let ((h (make-histogram-with-ranges-uniform 40 4.0 16.0)))
  (do ((i 0 (+ i 1)))
      ((= i 10000) (void))
    (histogram-increment! h (random-gaussian 10.0 2.0)))
  (histogram-plot h "Histogram of Gaussian Distribution"))

Where both the random-gaussian and histogram-increment! use provide/contract
and are within a loop.

-----Original Message-----
From: Robby Findler [mailto:robby at cs.uchicago.edu] 
Sent: Monday, October 04, 2004 7:53 AM
To: Williams, M. Douglas
Cc: plt-scheme at web-ext.cs.brown.edu
Subject: Re: [plt-scheme] Science Collection

At Mon, 4 Oct 2004 06:46:29 -0700, "Williams, M. Douglas" wrote:
> 3.  In the last week, I updated all of the modules to use provide/contract
> to define and enforce parameter (and result) types, ranges, and
> inter-argument constraints.  I really like the concept and think it's a
> great feature.  However, it seems (very subjective here) that my examples
> run about an order of magnitude slower than before.  [To be fair, nothing
> pre-compiled and much of that may be overhead due to compilation time when
> they are loaded.]  Does anyone have a good handle on the overhead
> with using contracts?

There is a known performance bug with contracts. If you refer to a
variable with a contract inside a loop, the performance is much worse
than if you refer to it outside a loop. 

For example, with this in one module:

  (define (f x) x)
  (provide/contract [f (integer? . -> . integer?)])

Then this is very very slow:

  (define (count n)
    (unless (zero? n)
      (f n)
      (count (- n 1))))

Whereas this:

  (define local-f f)
  (define (count n)
    (unless (zero? n)
      (local-f n)
      (count (- n 1))))

is not (still slower, but not absurdly so). We're working on a solution
to this, but haven't gotten one yet.

If you're seeing something else, perhaps a small example would help me
figure out what's going on.


Posted on the users mailing list.