[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simpe Gwydion question
Lame followup:
-- cmucl --
;; might be faster to use something other than loop. maybe.
;; assign each element to element-number + 1.64.
;; it took me lots of searching around to figure out the right type
;; declaration for dvec.
(defun vector-foo (dvec)
(declare (optimize (speed 3) (debug 0) (safety 0))
(type (simple-array double-float (*)) dvec))
(loop for i of-type fixnum from 0 below (length dvec) by 1 do
(setf (aref dvec i) (+ i 1.64d0))))
;; make a 1,000,000 element array, each type double-float, each element 0.0.
;; operate on it 1000 times.
(defun main ()
(let ((ary (make-array 1000000
:initial-element 0.0d0
:element-type 'double-float
:adjustable nil)))
(loop for i of-type fixnum from 1 to 1000 do
(vector-foo ary))))
-- cmucl --
;; i manually compiled vector-foo and main before doing this:
* (time (main))
Compiling LAMBDA NIL:
Compiling Top-Level Form:
Evaluation took:
48.92 seconds of real time
44.7476 seconds of user run time
0.062151 seconds of system run time
0 page faults and
8000008 bytes consed.
NIL
*
-- dylan --
/*
create a subclass of simple-vector that has double-float elements.
note that both simple-vector and double-float are actual classes.
*/
define constant <my-double-vector> =
limited(<simple-vector>, of: <double-float>);
/*
i'm lazy, so i don't tell the compiler all the types. let it figure
out what i is an integer or whatever; dvec.size is optimized from a
object slot access to a constant.
hopefully.
*/
define function vector-foo(dvec :: <my-double-vector>) => ()
for (i from 0 below dvec.size)
dvec[i] := i + 1.64;
end for;
end function vector-foo;
// create an array, run vector-foo() on it a thousand times, quit.
define function main(name, arguments)
let ary :: <my-double-vector> =
make(<my-double-vector>, size: 1000000, fill: 0.0);
for (i from 1 to 1000)
vector-foo(ary);
end for;
exit-application(0);
end function main;
// Invoke our main() function.
main(application-name(), application-arguments());
-- dylan --
% /usr/bin/time ./dylan-version
30.21 real 27.60 user 0.02 sys
%
-- c --
void vector_foo(double *dvec, int dvec_size)
{
int i;
for (i = 0; i < dvec_size; i++)
dvec[i] = i + 1.64;
}
/* made this a global because i was exceeding my stacksize limit */
double ary[1000000];
int main()
{
int i;
for (i = 0; i < 1000; i++)
vector_foo(ary, 1000000);
_exit(0);
}
-- c --
% /usr/bin/time ./foo
30.20 real 27.59 user 0.03 sys
%
athlon 800.