-- -*- mode: eiffel -*-
-- $Id: ary3.se,v 1.1 2001/05/31 02:27:48 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- Friedrich Dominicus points out that it is about twice as fast
-- when we substitute NATIVE_ARRAY for ARRAY. I've commented out
-- my original code below and now use NATIVE_ARRAY.
class ARY3
creation make
feature
make is
local
x: NATIVE_ARRAY[INTEGER];
y: NATIVE_ARRAY[INTEGER];
-- x: ARRAY[INTEGER];
-- y: ARRAY[INTEGER];
i,k,n: INTEGER;
do
if argument_count = 1 then
n := argument(1).to_integer
else
n := 1
end
x := x.calloc(n);
y := y.calloc(n);
-- !!x.make(0,n)
-- !!y.make(0,n)
from
i := 0
until
i = n
loop
x.put(i + 1, i)
i := i + 1
end
from
k := 0
until
k = 1000
loop
from
i := n-1
until
i < 0
loop
y.put(x.item(i) + y.item(i),i)
i := i - 1
end
k := k + 1
end
std_output.put_integer(y.item(0))
std_output.put_character(' ')
std_output.put_integer(y.item(n-1))
std_output.put_character('%N')
end
end