ID:153464
 
I don't suppose it matters much, but I've been wondering whether a while loop with a sleep at the end or a proc calling itself with spawn is better for an infinite loop. Has anyone noticed any differences between the two(especially efficiency-wise)?
Jon88 wrote:
I don't suppose it matters much, but I've been wondering whether a while loop with a sleep at the end or a proc calling itself with spawn is better for an infinite loop. Has anyone noticed any differences between the two(especially efficiency-wise)?

I can't say authoritatively, but I assume a sleep() is more efficient than a spawn().
The difference is probably minimal, but I would guess that sleep() is more efficient.
I don't suppose it matters much, but I've been wondering whether a while loop with a sleep at the end or a proc calling itself with spawn is better for an infinite loop. Has anyone noticed any differences between the two(especially efficiency-wise)?

Unless the core of the loop is very small I think the diffrence is probably going to be negligable.
I use spawn() for EVERYTHING. In fact, I have gone through all my programs and begun removing all calls to sleep and replacing them with the appropriate calls to spawn() where possible. There are a few cases in which it's not a good idea (like if you spawn in login to delay something, it's obviously not going to work). When creating an infinitely loop, I always use spawn() because the world profiler will list more "accurate" times from using spawn(). Whereas if you used a while()/sleep(), the times would increase indefinitely, thus not giving an accurate account.

I asked Lummox the other day (he currently has my source for Hood -- amazingly enough) if I overused spawn. He said that the calls looked good enough as they were. I suppose he was shaking his head in dismay as the words came out, due to the general mess of the code, but hey.
I have found that using spawn() does not create infinite loop error like the sleep() does. I may be wrong on that, but it was a quick little test I did last night on a little day/night engine I am currently working on. With sleep() it made it through a full loop of the proc before crashing. With spawn() it made it through a loop and a half before I got bored and turned it off. (ADD) :)
In response to Satans Spawn
Both of them avoid infinite loop errors.