lua-users home
lua-l archive

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


Lua does use fmod but it doesn't have exactly the same semantics. See the comment on luai_nummod on limits.h for details.

On Aug 24, 2018 4:42 AM, Dirk Laurie wrote: > > Given Lua's position as an extension language embedded in a C host, > would not simply invoking fmod from math.h be the obvious thing to do? > Op Do., 23 Aug. 2018 om 19:04 het Roberto Ierusalimschy > geskryf: > > > > > I've tested the performance of one program under Lua 5.1 / 5.2 / 5.3 / 5.4 > > > The program is just a calculator of SHA512 written for Lua 5.1, all bitwise > > > operations are emulated with arithmetic. > > > The code is here:  https://stackoverflow.com/a/51561685/6834680 > > > (the code consists of two files: the module and the testing/benchmarking > > > script) > > > > > > All Lua executables under test are 64-bit, built with the same script under > > > the same compiler. > > > So, the benchmarking is fair. > > > > > > > > > C:\>lua51.exe sha2for51_test.lua > > > CPU seconds:    12.371 > > > > > > C:\>lua52.exe sha2for51_test.lua > > > CPU seconds:    12.513 > > > > > > C:\>lua53.exe sha2for51_test.lua > > > CPU seconds:    16.801 > > > > > > C:\>lua54.exe sha2for51_test.lua > > > CPU seconds:    15.6 > > > > At least in my machine, this time difference mainly boils down to > > the mod operation. If I compile lua 5.4 using the old (but slightly > > wrong) definition for '%', Lua 5.4 runs 4% slower than Lua 5.1, which > > I think is due to the high number of coercions between integers and > > floats. > > > > We can try to improve the implementation of '%' for floats, but > > I am not sure it is worth, given that, with integers and bitwise > > operations, that kind of use of '%' for floats is much diminished. > > > > -- Roberto > >