Which of the example below is more efficient (even if there were a difference in nanoseconds):
for i in countup(1, 10)
echo $i
inc(i)
for i in ..<=10
echo $i
i = i + 1
Are both of them have the exact velocity?
Both samples are incorrect, they both don't compile.
Here are the correct samples:
for i in countup(1, 10):
echo i
for i in 1..10:
echo i
As to performance, running both programs 100 times took about 800 milliseconds. They are virtually the same, to no surprise.
I understand all the fallacies of this question, but...
Well, I was a little curious to see what would happen if I made some deductions about the purpose of the question, and did try to benchmark the following:
j = 0
benchmark "function":
for i in countup(1, x):
inc j
vs
j = 0
benchmark "operator":
for i in 1..x:
j = j + 1
The following code is only for without compiler optimization and on platforms that support rdtsc:
https://gist.github.com/lbmn/d424dd0c8c85fa195743356fc133235a
So now there's a new way to flip a coin! :P