William James
5/28/2016 2:20:00 PM
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