ceifa / wasmoon

A real lua 5.4 VM with JS bindings made with webassembly
MIT License
462 stars 27 forks source link

Benchmark Issues #58

Closed gottfriedleibniz closed 1 year ago

gottfriedleibniz commented 1 year ago

Hi, was experimenting with this library and noticed some issues w/ the benchmarking code:

Per the documentation of luaL_loadstring: "This function returns the same results as lua_load", which, if there are no errors, is a "compiled chunk as a Lua function on top of the stack". However, since heapsort.lua returns a function, the single call to lua_pcallk does not actually execute the heapsort, it returns the function to execute the heapsort, e.g.:

  1. Run plain heapsort
  2. runHeapsort
  3. startFengari

One potential solution:

    state.global.lua.lua_pcallk(state.global.address, 0, 1, 0, 0, null)
    state.global.lua.lua_pcallk(state.global.address, 0, 0, 0, 0, null)

Additionally, the Fengari bits require some tweaking, e.g.,

const startFengari = () => {
    const state = fengari.lauxlib.luaL_newstate()
    fengari.lualib.luaL_openlibs(state);

    console.time('Fengari')
    fengari.lauxlib.luaL_loadstring(state, fengari.to_luastring(heapsort))
    fengari.lua.lua_pcallk(state, 0, 1, 0, 0, null)
    fengari.lua.lua_pcallk(state, 0, 0, 0, 0, null)
    console.timeEnd('Fengari')
}