Overview
| Artifact ID: | 363cfe7d7aabb1b9f0219bab9056fc64b2c2ffacce747d0ffa3d0f5f3318e1d6 |
|---|---|
| Ticket: | 1860727fffffffffffffffffffffffffffffffff
PCRE optional regexp |
| User & Date: | sebres on 2017-11-17 14:52:47 |
Changes
- assignee changed to: "aku"
- closer changed to: "nobody"
- comment changed to:
Attached is a diff that adds a configure --with-pcre option, as well as -type classic|pcre -binary options to [regexp] (available in either build, only functional with --with-pcre). --with-pcre=/path/to/pcre (or have it installed in a "default" location). Initial testing shows that PCRE is significantly faster in all cases the the classic Spencer engine.
- icomment:
I've rebased it to newer 8.5 (many conflicts resolved) relative my branch sebres-8-5-timerate (in order to test performance also). Currently available on my github (see artificial PR <a href="https://github.com/sebres/tcl/pull/5">sebres/tcl#5</a>). Compared to original variant provided von Jeffrey with patch pcre-20080121, it is complete:-<br/> many bugs fixed, regsub working as expected now, more robust and faster<br/> and has better backwards compatibility to the classic NFA-regexp of tcl, e. g. UCP (Unicode properties for \d, \w, etc.) and many others.<br/> Additionally:<ul> <li>better UTF8 and UCP support;</li> <li>types are compiled now;</li> <li>I've fixed all known bugs (of the classic regexp) for this new engine;</li> <li>added DFA type (still draft, but it works well), thus for example<br/> `regexp -type dfa -inline {a|ab|abc} -abc-` returns dfa-alternatives `{abc ab a}` ;)</li> <li>new test-cases added in order to explain differences (advantages and disadvantages) of all 3 variants.</li> <li>I've also a build for windows resp. auto-scripts and makefile for windows, thus if somebody needs, just ask :)</li> </ul> Todo's:<ul> <li>I should review and rewrite a few of code pieces for better understanding and to avoid code duplication;</li> <li>`regexp -binary` for real binary capability through PCRE;</li> <li>`regexp -dict` for capturing named groups of PCRE;</li> <li>provide real DFA-workspace (ATM fixed in stack) with reallocate on demand if to small;</li> <li>docu.</li> </ul> As regards the performance, the PCRE as well as DFA are very faster as classic NFA of tcl (up to 10 times and on large regexp still faster). Here an excerpt as a foretaste:<code><pre> % timerate -calibrate {} % foreach t {c p d} { proc test_$t {} \ [string map [list _REENG_ $t] \ {puts _REENG_:[timerate {regsub -type _REENG_ -all -line {^((\d{2})-(\d{2})-(\d{2,4})|NULL)$} "10-10-2017\nNULL\n20-10-2017" {**\1**\2**}}]} ]; puts "% [info body test_$t]"; test_$t } % puts c:[timerate {regsub -type c -all -line {^((\d{2})-(\d{2})-(\d{2,4})|NULL)$} "10-10-2017\nNULL\n20-10-2017" {**\1**\2**}}] <b style="color:red">c:38.3610 µs/# 26049 # 26068.1 #/sec 999.266 nett-ms</b> % puts p:[timerate {regsub -type p -all -line {^((\d{2})-(\d{2})-(\d{2,4})|NULL)$} "10-10-2017\nNULL\n20-10-2017" {**\1**\2**}}] <b style="color:green">p:1.413072 µs/# 693365 # 707677 #/sec 979.775 nett-ms</b> % puts d:[timerate {regsub -type d -all -line {^((\d{2})-(\d{2})-(\d{2,4})|NULL)$} "10-10-2017\nNULL\n20-10-2017" {**\1**\2**}}] <b style="color:green">d:1.205143 µs/# 810168 # 829777 #/sec 976.368 nett-ms</b> </pre></code> Note DFA has not realy a back-references here (but match alternatives), just the regsub used in order to minimize overhead of some tcl internal by measure (round about setting of variables or creating the lists by -indices or -inline). Tested with PCRE 8.40. If interested by TCT I'll rebase it to fossil as soon as possible and provide my 8.6th and 8.7th branches for this. I'll just spare this work (rebase) if nobody needs it. Ah, yes, don't forget: Thanks to Jeffrey for the original work! - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- severity changed to: "Minor"