Speed test

new topic     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C1327E.46E70D60
	charset="iso-8859-1"

The enclosed file tests the speed of five different methods of doing the
same thing. According to the results, it seems that using "parallel"
sequences is faster than using sequences of sequences, when possible,
although it might be less clean.


------=_NextPart_000_0015_01C1327E.46E70D60
	name="Test.ex"
	filename="Test.ex"

constant M = 1000
sequence x, y, a, b, c, d

procedure one(integer n)
    x = rand(repeat(repeat(M, 4), n))
    for i = 1 to n do
	x[i][1] += x[i][2] - x[i][3] + x[i][4]
    end for 
end procedure

procedure two(integer n)
    a = rand(repeat(M, n))
    b = rand(repeat(M, n))
    c = rand(repeat(M, n))
    d = rand(repeat(M, n))
    for i = 1 to n do
	a[i] += b[i] - c[i] + d[i]
    end for
end procedure

procedure three(integer n)
    a = rand(repeat(M, n))
    b = rand(repeat(M, n))
    c = rand(repeat(M, n))
    d = rand(repeat(M, n))
    a += b - c + d
end procedure

procedure four(integer n)
    x = rand(repeat(repeat(M, 4), n))
    for i = 1 to n do
	y = x[i]
	y[1] += y[2] - y[3] + y[4]
	x[i] = y
    end for 
end procedure

procedure five(integer n)
    x = rand(repeat(repeat(M, 4), n))
    for i = 1 to n do
	y = x[i]
	x[i][1] += y[2] - y[3] + y[4]
    end for 
end procedure

procedure test()
    integer n, k
    atom t0
    k = 500
    n = 1000
    t0 = time()
    for i = 1 to k do
	one(n)
    end for
    ? time() - t0
    t0 = time()
    for i = 1 to k do
	two(n)
    end for
    ? time() - t0
    t0 = time()
    for i = 1 to k do
	three(n)
    end for
    ? time() - t0
    t0 = time()
    for i = 1 to k do
	four(n)
    end for
    ? time() - t0
    t0 = time()
    for i = 1 to k do
	five(n)
    end for
    ? time() - t0
end procedure

test()

------=_NextPart_000_0015_01C1327E.46E70D60--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu