LPegLJ
LPegLJ copied to clipboard
performance
Trying 1M iterations on a relatively complex lpeg.re pattern, these are the results:
$ time luajit test_lpeglj.lua|wc -l
1000000
real 0m49.544s
user 0m49.509s
sys 0m0.540s
$ time luajit test_lulpeg.lua|wc -l
1000000
real 0m18.219s
user 0m18.192s
sys 0m0.492s
$ time luajit test_lpeg.lua|wc -l
1000000
real 0m3.004s
user 0m3.022s
sys 0m0.143s
$ luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2020 Mike Pall. https://luajit.org/
is this expected?
I would have expected LuLPeg to be slower, but I don't remember benchmarking LPegLJ extensively...
LuLPeg compiles the parsers to Lua functions that LuaJIT can trace and compile to native code, but the branchiness of the grammars meant the compiler often balked (at the time I wrote it). I know that Mike was working on trace stitching which may have helped with these scenarios IIRC. If they landed (and assuming I'm not mistaken, it's been a while) it may explain the reason LuLPeg is now faster.
Just a idea (i don't have time to do it myself)
- try the
luajit test_lulpeg.lua
with jit disable :luajit -e 'jit.off()' test_lulpeg.lua
: it should become slower thanlpeglj
- try with the PUC/Rio Lua to have another bench reference (that doesn't have jit)
I was hoping to make it run faster, not slower..