Lua print performance, Windows vs Linux

256 Views Asked by At

Using C, having

typedef struct Entity {
    size_t id;
    char *luaFun;
} Entity;

and calling

void LuaEntityUpdate(Entity *entity, double dt) {
    lua_getglobal(L, entity->luaFun);
    lua_pushinteger(L, entity->id);
    lua_pushnumber(L, dt);
    lua_call(L, 2, 0);
}

to global (entity->luaFun = "entity_update")

function entity_update(id, dt)
    print("Entity updated ", id, " ", dt)
end

in a loop (single game frame) takes about:

  • 0.2 seconds for 128 Entities using Windows*
  • 0.2 seconds for 8096 Entities using Linux**

making Windows build roughly 64 times slower than Linux (same machine, running apps reduced to minimum, both using 100% of single core).

What may be the reason for such huge difference? Please see comments and edit below.

* Windows 10, Mingw-w64, from: "MingW-W64-builds", using Lua 5.3.5 binary releases

** Mint 16, gcc, Lua 5.3.5 build from official sources

-- EDIT

As suggested in the comments I have tried to measure the performance without printing any messages and BINGO! Without any kind of printing performance almost matches the Linux build.

Now, I have tried to replace the print with:

local w = print
w(...)

-

io.write(...)

-

local w = io.write
w(...)

but they all perform the same.

I have also tried to run the program from Windows command which is about 30% faster than console captured inside CLion.

Are there any tricks to make it faster on Windows? It would be great to have the logging utility available in lua parts, but even for debugging this is too slow for real-time apps.

Also: Changed title

0

There are 0 best solutions below