LPegLJ icon indicating copy to clipboard operation
LPegLJ copied to clipboard

performance

Open bjne opened this issue 4 years ago • 3 comments

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?

bjne avatar Jan 25 '21 17:01 bjne

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.

pygy avatar Jan 25 '21 20:01 pygy

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 than lpeglj
  • try with the PUC/Rio Lua to have another bench reference (that doesn't have jit)

tst2005 avatar Jan 26 '21 09:01 tst2005

I was hoping to make it run faster, not slower..

bjne avatar Jan 26 '21 10:01 bjne