lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2008/10/24 Jeff Wise <jwise@sealyrealty.com>:
> ➢ I wonder which one will be faster, assuming there is a difference?
>
> My guess is that it is OS-dependent. In the world I came from, "Open" is much more cycle intensive. In fact Open first answers the question "Does it exist?" before it does all its other processing (buffers, control blocks, connection to appropriate I/O routines, security, etc). In fact, I can't imagine how open would be less cycle intensive on any platform, but that is conjecture.

In theory the function retrieving the less information should be the
fastest. Open has to create a file descriptor, attributes('size') has
to get the size of the file after checking it's of a type which has a
size, attributes('mode') just checks the type.

However if you introduce caching (for the size attribute), or lazy
initialization (ie. the complete file descriptor is not really created
by open but only when effectively used) that can change the numbers.
Also io.open calls may be optimized by a JIT compiler (because it's a
standalone API function) while lfs methods may not be. That's why this
is very dependent on the setup.