It looks to me like the slowdown isn't entirely explained by contract
checking, or perhaps TR isn't generating the contracts I would have
guessed. With the program below, I see this output

cpu time: 1228 real time: 1228 gc time: 133
cpu time: 658 real time: 658 gc time: 18
cpu time: 80 real time: 81 gc time: 0

but would have expected the first two lines to be nearly the same.

Robby

#lang racket

(require (only-in math/number-theory divides?))

(define (divisible-by? x d)
  (= (modulo x d)
     0))

(module d racket/base
  (require racket/contract/base)
  (define (divisible-by? x d)
    (= (modulo x d)
       0))
  (provide
   (contract-out
    [divisible-by? (-> exact-integer? exact-integer? boolean?)])))

(require (prefix-in c: (submod "." d)))


(module+ main
  (time
   (for ([x (in-range 3 5000000)])
     (if (3 . divides? . x)
         x
         0)))

  (time
   (for ([x (in-range 3 5000000)])
     (if (3 . c:divisible-by? . x)
         x
         0)))

  (time
   (for ([x (in-range 3 5000000)])
     (if (x . divisible-by? . 3)
         x
         0))))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to