[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Pitfalls? - Changing Lisp to C (enlightened

William James

7/25/2015 6:55:00 AM

Brian Downing wrote:

> (defparameter *a* (make-array 1048576
> :element-type 'double-float
> :initial-element 1.0d0))
> (defparameter *b* (make-array 1048576
> :element-type 'double-float
> :initial-element 1.0d0))
....
> (defun vector-+-loop (x y)
> (declare (optimize (speed 3) (safety 0) (debug 0))
> (type (simple-array double-float) x y))
> (loop for i from 0 to (1- (length x))
> do (setf (aref x i) (+ (aref x i) (aref y i))))
> (values (aref x 0) (aref y 0)))
....
> * (time (vector-+-loop *a* *b*))
> ; Compiling LAMBDA NIL:
> ; Compiling Top-Level Form:
>
> ; Evaluation took:
> ; 0.03 seconds of real time
> ; 0.03 seconds of user run time
> ; 0.0 seconds of system run time
> ; 0 page faults and
> ; 32 bytes consed.
> ;
> 2.0d0
> 1.0d0

Gauche Scheme:

(use gauche.uvector)

(define a (make-f64vector 1048576 1.0))
(define b (make-f64vector 1048576 1.0))

(time
(f64vector-add! a b)
(values
(f64vector-ref a 0)
(f64vector-ref b 0)))

;(time (f64vector-add! a b) (values (f64vector-ref a 0) (f64vector-ref b ...
; real 0.016
; user 0.016
; sys 0.000
2.0
1.0

--
To make matters worse, while Norwegian women are increasingly unsafe in their
own capital, we hear calls for even more immigration, and 85% of our MPs pass
a law saying that we are guilty of discriminating against immigrants until
proven otherwise.
http://fjordman.blogspot.com/2005/07/norwegian-government-coveri...
1 Answer

William James

5/28/2016 2:20:00 PM

0

WJ wrote:

> Brian Downing wrote:
>
> > (defparameter a (make-array 1048576
> > :element-type 'double-float
> > :initial-element 1.0d0))
> > (defparameter b (make-array 1048576
> > :element-type 'double-float
> > :initial-element 1.0d0))
> ....
> > (defun vector-+-loop (x y)
> > (declare (optimize (speed 3) (safety 0) (debug 0))
> > (type (simple-array double-float) x y))
> > (loop for i from 0 to (1- (length x))
> > do (setf (aref x i) (+ (aref x i) (aref y i))))
> > (values (aref x 0) (aref y 0)))
> ....
> > * (time (vector-+-loop a b))
> > ; Compiling LAMBDA NIL:
> > ; Compiling Top-Level Form:
> >
> > ; Evaluation took:
> > ; 0.03 seconds of real time
> > ; 0.03 seconds of user run time
> > ; 0.0 seconds of system run time
> > ; 0 page faults and
> > ; 32 bytes consed.
> > ;
> > 2.0d0
> > 1.0d0
>
> Gauche Scheme:
>
> (use gauche.uvector)
>
> (define a (make-f64vector 1048576 1.0))
> (define b (make-f64vector 1048576 1.0))
>
> (time
> (f64vector-add! a b)
> (values
> (f64vector-ref a 0)
> (f64vector-ref b 0)))
>
> ;(time (f64vector-add! a b) (values (f64vector-ref a 0) (f64vector-ref b ...
> ; real 0.016
> ; user 0.016
> ; sys 0.000
> 2.0
> 1.0

OCaml:

let add_float_vectors a b =
for i = 0 to Array.length a - 1 do
a.(i) <- a.(i) +. b.(i)
done ;;

let a = Array.make 1048576 1.0 ;;
let b = Array.make 1048576 1.0 ;;

let t = Sys.time () in
for _ = 0 to 9 do
add_float_vectors a b
done ;
Printf.printf "%.3f sec.\n" ((Sys.time () -. t) /. 10.0) ;;

0.006 sec.

--
When the Israeli bombers and torpedo-planes were sent to attack and destroy the
ship, the Jewish commander, seeing that it was an American vessel, had
misgivings and reported to the High Command, which simply repeated the orders
to attack and sink the Liberty. www.revilo-oliver.com/rpo/Bit_of_Good_News.html