andgineer / TRegExpr

Regular expressions (regex), pascal.
https://regex.sorokin.engineer/en/latest/
MIT License
174 stars 63 forks source link

Optimize branch #354

Closed User4martin closed 11 months ago

User4martin commented 11 months ago

Optimize | branches

Fix for bug #352


                                                        Time     Before | Opt-Branch     | Match count
========================================================================================================
                                                  /Twain/ :       41 ms |      37 ms     |      2388
                                              /(?i)Twain/ :       58 ms |      58 ms     |      2657
                                             /[a-z]shing/ :      228 ms |     228 ms     |      1877
                             /Huck[a-zA-Z]+|Saw[a-zA-Z]+/ :       39 ms |      35 ms     |       396
                                                      /./ :      421 ms |     449 ms     |  18905427
                                                    /(.)/ :      660 ms |     707 ms     |  18905427
                                                      /e/ :       84 ms |      80 ms     |   1781425
                                                    /(e)/ :      105 ms |     103 ms     |   1781425
                                           /(?s).{1,45} / :       37 ms |      37 ms     |    475715
                                         /(?s)\G.{1,45} / :      164 ms |     144 ms     |     10616
                                         /\G(?s).{1,45} / :       15 ms |      15 ms     |     10616
                                          /(?s).{1,45}? / :      154 ms |     160 ms     |   3241534
                                        /(?s)\G.{1,45}? / :      169 ms |     146 ms     |     69431
                                        /\G(?s).{1,45}? / :       19 ms |      19 ms     |     69431
                                              /\b\w+nn\b/ :      230 ms |     226 ms     |       359
                                       /[a-q][^u-z]{13}x/ :      652 ms |     613 ms     |      4929
                            /Tom|Sawyer|Huckleberry|Finn/ :       42 ms |      39 ms     |      3015
                        /(?i)Tom|Sawyer|Huckleberry|Finn/ :      164 ms |     142 ms +   |      4820
                    /.{0,2}(Tom|Sawyer|Huckleberry|Finn)/ :     2123 ms |    1636 ms +++ |      3015
                    /.{2,4}(Tom|Sawyer|Huckleberry|Finn)/ :     2330 ms |    1820 ms +++ |      2220
                      /Tom.{10,25}river|river.{10,25}Tom/ :       56 ms |      50 ms     |         2
                                           /[a-zA-Z]+ing/ :      585 ms |     574 ms     |     95863
                                  /\s[a-zA-Z]{0,12}ing\s/ :      261 ms |     257 ms     |     67810
                          /([A-Za-z]awyer|[A-Za-z]inn)\s/ :      527 ms |     521 ms     |       313
                              /["'][^"']{0,30}[?!\.]["']/ :       80 ms |      74 ms     |      9857
                                /Tom(.{3,3}|.{5,5})*Finn/ :     2748 ms |    2724 ms     |        11
                                    /Tom(...|.....)*Finn/ :     1271 ms |    1277 ms     |        11
                                   /Tom(...|.....)*?Finn/ :     1380 ms |    1337 ms     |        11
                      /Tom((...|.....){2,9}\s){1,5}?Finn/ :     3638 ms |    3603 ms     |        11
                      /Tom((...|.....){2,9}?\s){1,5}Finn/ :     3613 ms |    3605 ms     |        11
                                        /\G(?is).(?=.*$)/ :      916 ms |     947 ms     |  20045118
                                /\G(?is).(?=(.){1,5}?$)?/ :     3293 ms |    3302 ms     |  20045118
                                       /\G(?is).(?=.*+$)/ :      880 ms |     933 ms     |  20045118
                /\G(?is).{10,10}(?=(e|y|on|fin|.){0,20})/ :     1834 ms |    1408 ms +++ |   2004511
              /\G(?is).{10,10}(?=(?>e|y|on|fin|.){0,20})/ :     1837 ms |    1414 ms +++ |   2004511
                                          /Tom(?!.*Finn)/ :       41 ms |      37 ms     |      2441
     /(?i)(?>[aeoui][bcdfghjklmnpqrstvwxyz \r\n]*){1,40}/ :      597 ms |     576 ms     |    579843
                          /(?i)[ bdlm][abdegij][mnoprst]/ :      224 ms |     214 ms     |    788955
Total:                                                         31531 ms |   29562 ms     |
Alexey-T commented 11 months ago

Great work! i will read it tomorrow. today is bad day in russia, some victims of criminals.