[racket] typed racket slow?

From: Manfred Lotz (manfred.lotz at arcor.de)
Date: Wed May 8 05:32:07 EDT 2013

Hi there,
I did a small test using typed racket. 

This is an example from the documentation:

#lang typed/racket
;; test.rkt

(struct: pt ([x : Float] [y : Float]))

(: distance (pt pt -> Float))
(define (distance p1 p2)
  (sqrt (+ (sqr (- (pt-x p2) (pt-x p1)))
           (sqr (- (pt-y p2) (pt-y p1))))))

(distance (pt 1.2 2.1) (pt 4.3 5.6))

This is the untyped version:
#lang racket
;; utest.rkt

(struct pt (x y))

(define (distance p1 p2)
  (sqrt (+ (sqr (- (pt-x p2) (pt-x p1)))
           (sqr (- (pt-y p2) (pt-y p1))))))

(distance (pt 1.2 2.1) (pt 4.3 5.6))


Now running both:
time racket test.rkt
4.675467891024383
racket test.rkt  1.24s user 0.08s system 99% cpu 1.333 total


time racket utest.rkt
4.675467891024383
racket utest.rkt  0.22s user 0.03s system 99% cpu 0.248 total


It seems the typed version needs a lot of time for the type checking.
The time for time checking could be cut mostly by:

raco exe test.rkt
time ./test
4.675467891024383
./test  0.49s user 0.03s system 99% cpu 0.531 total

But still runtime is more than twice as long. I could get the
impression that typed racket is generally slower.


Question: Is there any conclusion to be drawn from this (like that
typed racket is slower than 'normal' racket)? Or is my test just a bad
test? 


-- 
Manfred













Posted on the users mailing list.