Last active
December 10, 2018 00:24
-
-
Save sandacn/881d3192887b116ce6fcc39433335376 to your computer and use it in GitHub Desktop.
PHP 7.3 upgrade to PCRE2 performance test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
### run this with php 7.3 and php lower version such as php 7.2 | |
### time php re_bench.php | |
### time php73 re_bench.php | |
$regex_list = [ | |
'#Twain#', | |
'#(?i)Twain#', | |
'#[a-z]shing#', | |
'#Huck[a-zA-Z]+|Saw[a-zA-Z]+#', | |
'#\b\w+nn\b#', | |
'#[a-q][^u-z]{13}x#', | |
'#Tom|Sawyer|Huckleberry|Finn#', | |
'#(?i)Tom|Sawyer|Huckleberry|Finn#', | |
'#.{0,2}(Tom|Sawyer|Huckleberry|Finn)#', | |
'#.{2,4}(Tom|Sawyer|Huckleberry|Finn)#', | |
'#Tom.{10,25}river|river.{10,25}Tom#', | |
'#[a-zA-Z]+ing#', | |
'#\s[a-zA-Z]{0,12}ing\s#', | |
'#([A-Za-z]awyer|[A-Za-z]inn)\s#', | |
'#["\'][^"\']{0,30}[?!\.][\"\']#', | |
//'#\u221E|\u2713#', // 这里注释掉是因为在 PHP7.3之前还不支持这种语法 | |
'#\p{Sm}#', | |
]; | |
$file_content_list = []; | |
$files = [ | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'32.txt', | |
'1K.txt', | |
'1K.txt', | |
'1K.txt', | |
'1K.txt', | |
'1K.txt', | |
'1K.txt', | |
'1K.txt', | |
'32K.txt', | |
'32K.txt', | |
'32K.txt', | |
'1MB.txt', | |
]; | |
// path to regex data, @see https://github.com/rust-lang/regex/tree/master/bench/src/data | |
$prefix = '$rust-lang-dir/regex/regex/bench/src/data'; | |
foreach ($files as $_f) { | |
$_path = $prefix . '/' . $_f; | |
$file_content_list[] = file_get_contents($_path); | |
} | |
foreach ($regex_list as $_r) { | |
foreach ($file_content_list as $_content) { | |
$match_num = preg_match($_r, $_content, $matches); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment