ps:let alone the code complexity of closure implementation of the same task.
相关问题
- How to get the return code of a shell script in lu
- Faster loop: foreach vs some (performance of jsper
- Why wrapping a function into a lambda potentially
- Ado.net performance:What does SNIReadSync do?
- Device support warning : Google play 2019
相关文章
- DOM penalty of using html attributes
- Which is faster, pointer access or reference acces
- Django is sooo slow? errno 32 broken pipe? dcramer
- Understanding the difference between Collection.is
- parallelizing matrix multiplication through thread
- How to determine JS bottlenecks in React Native co
- Difference between SuspendLayout and BeginUpdate
- Efficient Rolling Max and Min Window
The memory overhead for a closure will be less than for a coroutine (unless you've got a lot of "upvalues" in the closure, and none in the coroutine). Also the time overhead for invoking the closure is negligible, whereas there is some small overhead for invoking the coroutine. From what I've seen, Lua does a pretty good job with coroutine switches, but if performance matters and you have the option not to use a coroutine, you should explore that option.
If you want to do benchmarks yourself, for this or anything else in Lua:
You use
collectgarbage("collect");collectgarbage("count")
to report the size of all non-garbage-collectable memory. (You may want to do "collect" a few times, not just one.) Do that before and after creating something (a closure, a coroutine) to know how much size it consumes.You use
os.clock()
to time things.See also Programming in Lua on profiling.