Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop speed
#1
What is the fastest way for a loop?

Code:
Copy      Help
int i=3
for i 3 sqrt(a)+1 2
,if(a%i=0) ret 0

or

Code:
Copy      Help
int i=3
;bucle
if(i<=sqrt(a)+1)
,if(a%i=0) ret 0
,i+2
,goto bucle

or

Code:
Copy      Help
int i=3
rep
,if(a%i=0) ret 0
,i+2
,if(i>sqrt(a)+1) break

or

...

in my test:
1) aprox 100 ms
2) aprox 500 ms
3) aprox 500 ms
#2
All should be similar if same code inside. Here for is faster because sqrt is called once.
#3
Ok. Thanks.


Forum Jump:


Users browsing this thread: 1 Guest(s)