wasmoon
wasmoon copied to clipboard
Benchmark Issues
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.:
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')
}