[racket] deceptive perfomance for typed racket in integer division

From: daniel rupis (danielrupistralizavez at yahoo.es)
Date: Tue Dec 11 11:08:12 EST 2012

Pierpaolo Bernardi <olopierpa at ...> writes:

> 
> On Tue, Dec 11, 2012 at 4:03 PM, daniel rupis
> <danielrupistralizavez at ...> wrote:
> >
> >  I was comparing some code in Qi with that of sbcl, I posted a question in
> > comp.lang.lisp asking for a way to improve the perfomance, WJ gave a typed
> > racket version that was slower than sbcl and also much slower than cpp.
> 
> The sbcl version is unsafe and uses numbers declared to be in a small range.
> 
> To not compare apples to pears, please measure the version below which
> uses unsafe features of racket similar to the ones in the sbcl
> version.
> 
> On my machine it produces:
> 
> c:\Users\bernardip\Documents\Scheme>testp
> 3340
> cpu time: 2594 real time: 2685 gc time: 0
> 
> Remember to generate an executable, to obtain the maximum speed.
> 
> Alternatively, compare your racket version against sbcl with (declare
> (optimize safety 3))
> 
> Cheers
> P.
> 
> ====
> 
> #lang racket
> 
> (require racket/unsafe/ops)
> 
> (define (divisible-rec i j)
>   (cond ((unsafe-fx= j 1)
>          #f)
>         ((unsafe-fx= 0 (unsafe-fxmodulo i j))
>          #t)
>         (else
>          (divisible-rec i (unsafe-fx+ -1 j)))))
> 
> (define (divisible n)
>   (divisible-rec n (unsafe-fx+ -1 n)))
> 
> (define (total-primes k)
>   (for/sum ([n (in-range 2 (add1 k))])
>     (if (divisible n)
>       0
>       1)))
> 
> (define (test)
>   (time (displayln (total-primes 30999))))
> 
> (test)
> 
> ========
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
> 
> 

 Comparison: better with 60999 to minimize any other small time not related to
the computations. 

sbcl 

 (time (totalprimes 60999))

Evaluation took:
  20.394 seconds of real time
  20.381273 seconds of total run time (20.377273 user, 0.004000 system)
  99.94% CPU
  42,720,745,799 processor cycles
  0 bytes consed
  
6145

racket on the same machine ubuntu 12.04
user at ubuntu:~/lang/racket/racket$ uname -a
Linux ubuntu 3.2.0-34-generic #53-Ubuntu SMP Thu Nov 15 10:48:16 UTC 2012 x86_64
x86_64 x86_64 GNU/Linux

Welcome to Racket v5.3.1.


(define (test)
  (time (displayln (total-primes 60999))))> > > > 
> (test)
6145
cpu time: 39170 real time: 39156 gc time: 0

 Using ubuntu 12.04 and racket 


Posted on the users mailing list.