I was very curious about what you were talking about, as I saw wildly different numbers (in line with what I'd seen before).

However, I did the following test:

|> ~/tools/racket/6.1.1/bin/racket typed_divide.rkt
cpu time: 536 real time: 537 gc time: 27
cpu time: 347 real time: 347 gc time: 4
cpu time: 87 real time: 84 gc time: 0

|> ~/tools/racket/6.2.0/bin/racket typed_divide.rkt
cpu time: 567 real time: 565 gc time: 10
cpu time: 960 real time: 958 gc time: 13
cpu time: 83 real time: 84 gc time: 0

|> ~/tools/racket/6.2.1/bin/racket typed_divide.rkt
cpu time: 600 real time: 601 gc time: 70
cpu time: 970 real time: 974 gc time: 23
cpu time: 86 real time: 85 gc time: 0

The below program is what's being run:

#lang racket/base

(module t typed/racket/base
  (: divides? : Integer Integer -> Boolean)
  (define (divides? a b)
    (cond
      [(zero? a)  #f]
      [else  (= (remainder b a) 0)]))
  (provide divides?))

(module c racket/base
  (require racket/contract/base)
  (define (divides? a b)
    (cond [(zero? a)  #f]
      [else  (= (remainder b a) 0)]))
  (provide
    (contract-out
      [divides? (-> exact-integer? exact-integer? boolean?)])))

(module no-contract racket/base
  (define (divides? a b)
    (cond
      [(zero? a)
       #f]
      [else
        (= (remainder b a) 0)]))
  (provide divides?))

(require (prefix-in with-contract: (submod "." c)))
(require (prefix-in typed: (submod "." t)))
(require (prefix-in no-contract: (submod "." no-contract)))

(time
  (for ([x (in-range 3 5000000)])
    (if (3 . with-contract:divides? . x)
      x
      0)))

(time
  (for ([x (in-range 3 5000000)])
    (if (3 . typed:divides? . x)
      x
      0)))

(time
  (for ([x (in-range 3 5000000)])
    (if (3 . no-contract:divides? . x)
      x
      0)))


On Mon, 24 Aug 2015, Robby Findler wrote:

My message below is not doing the right test. This is the right test
and it produces the expected result, namely that the TR version runs a
bit faster (presumably because of type-based optimizations that TR
does).

Robby

#lang racket

(module t typed/racket/base
 (: divides? : Integer Integer -> Boolean)
 (define (divides? a b)
   (cond [(zero? a)  #f]
         [else  (= (remainder b a) 0)]))
 (provide divides?))

(module c racket/base
 (require racket/contract/base)
 (define (divides? a b)
   (cond [(zero? a)  #f]
         [else  (= (remainder b a) 0)]))
 (provide
  (contract-out
   [divides? (-> exact-integer? exact-integer? boolean?)])))

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

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

(time
(for ([x (in-range 3 5000000)])
  (if (3 . t:divides? . x)
      x
      0)))


On Mon, Aug 24, 2015 at 8:18 AM, Robby Findler
<ro...@eecs.northwestern.edu> wrote:
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