so for awhile now I have been profiling everything in computercraft to see exactly what runs with what speeds and today I happened to look at loops at their bare minimum.
while true do
for i=1,1000 do
print(i)
end
end
now assuming we are completely ignoring the standard yield time in computercraft I noticed each time it completes that for loop the next one will be a little bit faster. this seemed to cap out at about a .5 second difference going through the whole loop between the first and last times. This isn't too shocking since I am assuming lua must use some type of cache then to handle stuff like that. The really weird part is when you through sleep into the mix (mind you this is with no other computers on the single player world)
while true do
for i=1,1000
sleep(0.0)
end
end
each loop this appeared to actually take longer to execute. roughly about a .00819 second difference from first to last test loop per sleep. the really weird part was when i broke out of multishell with term.redirect(term.native()). This actually Increased the amount it slowed down each loop these are the times for loops 1, 50, and 100
33.79999999996926
40.79999999996289
48.19999999995616
the 100th loop actually had NEARLY the same amount of time to execute as the last loop without redirecting out of multishell. can anyone actually explain what is going on here to help my further tests later today?
EDIT: I should clarify the time decrease in other functions such as .5 in print was almost immediate usually saving that by the second loop and staying the same during the test. Using sleep the time gradually increased with each loop run