Type atom faster than type integer?

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

Hi,

By logic and by what I think I've read in Euphoria documentation, a more restrictive type should be used whenever possible.

I would presume that a more restrictive type (like integer) would enable faster executions of code, instead of a more loose type (like atom).

atom t0   
integer n 
sequence b_lst 
sequence prime_lst 
 
n = 100000000 
b_lst = repeat( 1, n )   
prime_lst = {}   
 
t0 = time() 
   
for prime = 2 to n do   
	if b_lst[prime] then   
		prime_lst = append(prime_lst, prime )   
		for i = prime * 2  to n by prime do   
			b_lst[i] = 0   
		end for   
	end if   
end for   
   
 
? time() - t0  

Running this version using integer n results in 6.060000002 seconds of runtime.

If that declaration is changed to atom n, the execution time drops a bit to 6.050000001 seconds.

Why does this happen?

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

Search



Quick Links

User menu

Not signed in.

Misc Menu