Re: if statement optimization

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

I setup the example:

constant COUNT = 100000000 
constant HALF_COUNT = COUNT/2 
 
atom t1 = time() 
 
function case_one(integer i) 
  if i > HALF_COUNT then 
    return i 
  end if 
   
  return i 
end function 
 
function case_two(integer i) 
  if i > HALF_COUNT then 
    return i 
  else 
	return i 
  end if 
end function 
 
integer a = 1 
 
for i = 1 to COUNT do 
  a = case_one(i) 
end for 
 
puts(1, "Case One: ") 
? time() - t1 
t1 = time() 
 
for i = 1 to COUNT do 
  a = case_two(i) 
end for 
 
puts(1, "Case Two: ") 
? time() - t1 

and when running, I get:

C:\Users\Jeremy\Desktop>exwc test.ex 
Case One: 3.198 
Case Two: 3.200 
C:\Users\Jeremy\Desktop>exwc test.ex 
Case One: 3.198 
Case Two: 3.198 
C:\Users\Jeremy\Desktop>exwc test.ex 
Case One: 3.197 
Case Two: 3.198 

Jeremy

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

Search



Quick Links

User menu

Not signed in.

Misc Menu