[racket] flexpt being very slow

From: Dmitry Cherkassov (dcherkassov at gmail.com)
Date: Mon Sep 9 17:29:09 EDT 2013

Hi.

Please consider this program.
Why is flexpt so slow?

I get 20 ms vs 669 ms (for flexpt).

>------------------------------------------------------------------------<

#lang typed/racket
(require racket/flonum)

(define Sz 3000000)
(define test-vec
    (for/flvector #:length Sz ([i (in-range Sz)]) (random)))

(: sum-vec : FlVector -> Flonum)
(define (sum-vec v)
  (for/fold ([S 0.0]) ([e (in-flvector v)])
    (fl+ (fl* e e) S)))

(: sum-vec-expt : FlVector -> Flonum)
(define (sum-vec-expt v)
  (for/fold ([S 0.0]) ([e (in-flvector v)])
    (fl+ (flexpt e 2.0) S)))

(printf "plain sqr\n")
(time (sum-vec test-vec))

(printf "sqr using flexpt\n")
(time (sum-vec-expt test-vec))

>----------------------------------------------------------------------------<

Thanks.

P.S Racket version is 5.3.3

-- 
With best regards,
Dmitry

Posted on the users mailing list.