Re: something like 'abs()' ???

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

-- Use the following code to determine which
-- abs() function is faster. Interesting!!!

include get.e
object junk

with warning

function abs(integer x)
	if x > 0 then
		return x
	end if
	return -x
end function

function abs2(integer x)
	if x < 0 then
		return -x
	end if
	return x
end function

integer test_time, tester, counter
atom timer

test_time = 5 -- change this for shorter/longer testing time

counter = 0
puts(1,"Testing abs(1)\t")
timer = time() + test_time
while timer > time() do
	counter += 1
	tester = abs( 1 )
end while
?counter

counter = 0
puts(1,"Testing abs2(1)\t")
timer = time() + test_time
while timer > time() do
	counter += 1
	tester = abs2( 1 )
end while
?counter

counter = 0
puts(1,"Testing abs(-1)\t")
timer = time() + test_time
while timer > time() do
	counter += 1
	tester = abs( -1 )
end while
?counter

counter = 0
puts(1,"Testing abs2(-1)\t")
timer = time() + test_time
while timer > time() do
	counter += 1
	tester = abs2( -1 )
end while
?counter

junk = wait_key()

-- end of test code

-=ck
"Programming in a state of EUPHORIA."

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

Search



Quick Links

User menu

Not signed in.

Misc Menu