3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function check($w) { $t = strlen($w); if($t < 5 || $w[0] == '-' || $w[$t-1] == '-' || $w[strpos($w, "-") + 1] == '-') return false; return true; } $a = array ("safety", "safet-", "s-a-fe", "-safet", "s7-45", "s--fs"); $t1 = microtime(true); $c = 0; for ($i = 0; $i < 100000; $i ++ ){ foreach ($a as $w) { if (check($w)) $c ++; //echo $w, PHP_EOL; } } $t2 = microtime(true); echo "time without regex: ", $t2 - $t1, " n=" , $c, PHP_EOL; $t1 = microtime(true); $c = 0; for ($i = 0; $i < 100000; $i ++ ){ foreach ($a as $w) { if (preg_match('/^(?=.{5,6}$)[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/', $w)) $c ++; //echo $w, PHP_EOL; } } $t2 = microtime(true); echo "time with regex: ", $t2 - $t1, " n=", $c;
Output for 7.1.0
time without regex: 0.15396285057068 n=300000 time with regex: 0.078562021255493 n=300000
Output for 7.0.14
time without regex: 0.15707898139954 n=300000 time with regex: 0.065376996994019 n=300000
Output for 7.0.6
time without regex: 0.10268211364746 n=300000 time with regex: 0.10211205482483 n=300000
Output for 7.0.5
time without regex: 0.10053110122681 n=300000 time with regex: 0.10362696647644 n=300000
Output for 7.0.4
time without regex: 0.101557970047 n=300000 time with regex: 0.071595191955566 n=300000
Output for 7.0.3
time without regex: 0.10675692558289 n=300000 time with regex: 0.10358095169067 n=300000
Output for 7.0.2
time without regex: 0.098241090774536 n=300000 time with regex: 0.10103011131287 n=300000
Output for 7.0.1
time without regex: 0.10801911354065 n=300000 time with regex: 0.10601687431335 n=300000
Output for 7.0.0
time without regex: 0.10767388343811 n=300000 time with regex: 0.10488104820251 n=300000
Output for hhvm-3.12.0
time without regex: 0.23441481590271 n=300000 time with regex: 0.13037085533142 n=300000
Output for hhvm-3.10.0
time without regex: 0.28356313705444 n=300000 time with regex: 0.14072799682617 n=300000
Output for 5.6.28
time without regex: 0.32155299186707 n=300000 time with regex: 0.076389074325562 n=300000
Output for 5.6.21
time without regex: 0.27432894706726 n=300000 time with regex: 0.30961608886719 n=300000
Output for 5.6.20
time without regex: 0.26627898216248 n=300000 time with regex: 0.30996203422546 n=300000
Output for 5.6.19
time without regex: 0.28397083282471 n=300000 time with regex: 0.2774121761322 n=300000
Output for 5.6.18
time without regex: 0.26626205444336 n=300000 time with regex: 0.27605795860291 n=300000
Output for 5.6.17
time without regex: 0.27966499328613 n=300000 time with regex: 0.31112408638 n=300000
Output for 5.6.16
time without regex: 0.28009796142578 n=300000 time with regex: 0.30745005607605 n=300000
Output for 5.6.15
time without regex: 0.28449988365173 n=300000 time with regex: 0.30788111686707 n=300000
Output for 5.6.14
time without regex: 0.2736279964447 n=300000 time with regex: 0.30773687362671 n=300000
Output for 5.6.13
time without regex: 0.29123020172119 n=300000 time with regex: 0.30698585510254 n=300000
Output for 5.6.12
time without regex: 0.26174807548523 n=300000 time with regex: 0.30826997756958 n=300000
Output for 5.6.11
time without regex: 0.29857707023621 n=300000 time with regex: 0.32956695556641 n=300000
Output for 5.6.10
time without regex: 0.31894516944885 n=300000 time with regex: 0.33644199371338 n=300000
Output for 5.6.9
time without regex: 0.27340412139893 n=300000 time with regex: 0.30619096755981 n=300000
Output for 5.6.8
time without regex: 0.27492094039917 n=300000 time with regex: 0.30594706535339 n=300000
Output for 5.6.7
time without regex: 0.21901607513428 n=300000 time with regex: 0.2527129650116 n=300000
Output for 5.5.35
time without regex: 0.28546404838562 n=300000 time with regex: 0.31752705574036 n=300000
Output for 5.5.34
time without regex: 0.27890110015869 n=300000 time with regex: 0.31382203102112 n=300000
Output for 5.5.33
time without regex: 0.29269790649414 n=300000 time with regex: 0.28200316429138 n=300000
Output for 5.5.32
time without regex: 0.35467195510864 n=300000 time with regex: 0.40839290618896 n=300000
Output for 5.5.31
time without regex: 0.27610111236572 n=300000 time with regex: 0.31051301956177 n=300000
Output for 5.5.30
time without regex: 0.27833819389343 n=300000 time with regex: 0.31277298927307 n=300000
Output for 5.5.29
time without regex: 0.29297304153442 n=300000 time with regex: 0.32233810424805 n=300000
Output for 5.5.28
time without regex: 0.29355907440186 n=300000 time with regex: 0.31106781959534 n=300000
Output for 5.5.27
time without regex: 0.2684280872345 n=300000 time with regex: 0.30203700065613 n=300000
Output for 5.5.26
time without regex: 0.28461503982544 n=300000 time with regex: 0.31138586997986 n=300000
Output for 5.5.25
time without regex: 0.30196404457092 n=300000 time with regex: 0.32545709609985 n=300000
Output for 5.5.24
time without regex: 0.29308605194092 n=300000 time with regex: 0.3099479675293 n=300000
Output for 5.4.45
time without regex: 0.48855090141296 n=300000 time with regex: 0.51034307479858 n=300000
Output for 5.4.44
time without regex: 0.48600888252258 n=300000 time with regex: 0.40743088722229 n=300000
Output for 5.4.43
time without regex: 0.44480681419373 n=300000 time with regex: 0.54590702056885 n=300000
Output for 5.4.42
time without regex: 0.44600701332092 n=300000 time with regex: 0.40651392936707 n=300000
Output for 5.4.41
time without regex: 0.46036005020142 n=300000 time with regex: 0.44405698776245 n=300000
Output for 5.4.40
time without regex: 0.48095893859863 n=300000 time with regex: 0.42564487457275 n=300000
Output for 5.4.39
time without regex: 0.57864809036255 n=300000 time with regex: 0.51794099807739 n=300000
Output for 5.4.38
time without regex: 1.5143349170685 n=300000
Process exited with code 137.
Output for 5.4.37
time without regex: 1.5966260433197 n=300000
Process exited with code 137.
Output for 5.4.36
time without regex: 1.3780310153961 n=300000
Process exited with code 137.
Output for 5.4.35
time without regex: 0.90718388557434 n=300000 time with regex: 1.0508580207825 n=300000
Output for 5.4.34
time without regex: 1.1407270431519 n=300000
Process exited with code 137.
Output for 5.4.32
time without regex: 0.3103461265564 n=300000 time with regex: 0.29824113845825 n=300000
Output for 5.4.31
time without regex: 0.31706714630127 n=300000 time with regex: 0.34160089492798 n=300000
Output for 5.4.30
time without regex: 0.35157990455627 n=300000 time with regex: 0.32032608985901 n=300000
Output for 5.4.29
time without regex: 0.35410094261169 n=300000 time with regex: 0.35685205459595 n=300000
Output for 5.4.28
time without regex: 0.34462189674377 n=300000 time with regex: 0.35829591751099 n=300000
Output for 5.4.27
time without regex: 0.33314514160156 n=300000 time with regex: 0.3287570476532 n=300000
Output for 5.4.26
time without regex: 0.33979392051697 n=300000 time with regex: 0.31210398674011 n=300000
Output for 5.4.25
time without regex: 0.33364009857178 n=300000 time with regex: 0.32600808143616 n=300000
Output for 5.4.24
time without regex: 0.33225893974304 n=300000 time with regex: 0.32536888122559 n=300000
Output for 5.4.23
time without regex: 0.37605905532837 n=300000 time with regex: 0.32057595252991 n=300000
Output for 5.4.22
time without regex: 0.32647895812988 n=300000 time with regex: 0.35207796096802 n=300000
Output for 5.4.21
time without regex: 0.31898093223572 n=300000 time with regex: 0.33239197731018 n=300000
Output for 5.4.20
time without regex: 0.33289909362793 n=300000 time with regex: 0.34669208526611 n=300000
Output for 5.4.19
time without regex: 0.33884501457214 n=300000 time with regex: 0.37210607528687 n=300000
Output for 5.4.18
time without regex: 0.39188694953918 n=300000 time with regex: 0.32822489738464 n=300000
Output for 5.4.17
time without regex: 0.36885714530945 n=300000 time with regex: 0.33141708374023 n=300000
Output for 5.4.16
time without regex: 0.35117292404175 n=300000 time with regex: 0.34845399856567 n=300000
Output for 5.4.15
time without regex: 0.32326197624207 n=300000 time with regex: 0.37872195243835 n=300000
Output for 5.4.14
time without regex: 0.34759306907654 n=300000 time with regex: 0.35430502891541 n=300000
Output for 5.4.13
time without regex: 0.32893490791321 n=300000 time with regex: 0.43894290924072 n=300000
Output for 5.4.12
time without regex: 0.35841393470764 n=300000 time with regex: 0.50594091415405 n=300000
Output for 5.4.11
time without regex: 0.42572999000549 n=300000 time with regex: 0.35821199417114 n=300000
Output for 5.4.10
time without regex: 0.37860107421875 n=300000 time with regex: 0.34247207641602 n=300000
Output for 5.4.9
time without regex: 0.33839583396912 n=300000 time with regex: 0.38107085227966 n=300000
Output for 5.4.8
time without regex: 0.33742904663086 n=300000 time with regex: 0.35189914703369 n=300000
Output for 5.4.7
time without regex: 0.40119695663452 n=300000 time with regex: 0.36915493011475 n=300000
Output for 5.4.6
time without regex: 0.43202114105225 n=300000 time with regex: 0.38872504234314 n=300000
Output for 5.4.5
time without regex: 0.38684391975403 n=300000 time with regex: 0.39325308799744 n=300000
Output for 5.4.4
time without regex: 0.34442114830017 n=300000 time with regex: 0.40203809738159 n=300000
Output for 5.4.3
time without regex: 0.3198721408844 n=300000 time with regex: 0.36385989189148 n=300000
Output for 5.4.2
time without regex: 0.36650395393372 n=300000 time with regex: 0.3908748626709 n=300000
Output for 5.4.1
time without regex: 0.32379293441772 n=300000 time with regex: 0.38622999191284 n=300000
Output for 5.4.0
time without regex: 0.34195780754089 n=300000 time with regex: 0.33634805679321 n=300000
Output for 5.3.29
time without regex: 0.4222297668457 n=300000 time with regex: 0.34326004981995 n=300000
Output for 5.3.28
time without regex: 0.415687084198 n=300000 time with regex: 0.34967708587646 n=300000
Output for 5.3.27
time without regex: 0.41066408157349 n=300000 time with regex: 0.3614559173584 n=300000
Output for 5.3.26
time without regex: 0.41778302192688 n=300000 time with regex: 0.36081314086914 n=300000
Output for 5.3.25
time without regex: 0.43578791618347 n=300000 time with regex: 0.39818501472473 n=300000
Output for 5.3.24
time without regex: 0.4449770450592 n=300000 time with regex: 0.39393496513367 n=300000
Output for 5.3.23
time without regex: 0.39952802658081 n=300000 time with regex: 0.36113381385803 n=300000
Output for 5.3.22
time without regex: 0.42472386360168 n=300000 time with regex: 0.4245879650116 n=300000
Output for 5.3.21
time without regex: 0.43839502334595 n=300000 time with regex: 0.41654992103577 n=300000
Output for 5.3.20
time without regex: 0.44639015197754 n=300000 time with regex: 0.39894485473633 n=300000
Output for 5.3.19
time without regex: 0.44918489456177 n=300000 time with regex: 0.40775990486145 n=300000
Output for 5.3.18
time without regex: 0.40290284156799 n=300000 time with regex: 0.35677599906921 n=300000
Output for 5.3.17
time without regex: 0.42046189308167 n=300000 time with regex: 0.44080495834351 n=300000
Output for 5.3.16
time without regex: 0.43571996688843 n=300000 time with regex: 0.42263197898865 n=300000
Output for 5.3.15
time without regex: 0.42001605033875 n=300000 time with regex: 0.37560105323792 n=300000
Output for 5.3.14
time without regex: 0.44249510765076 n=300000 time with regex: 0.42845106124878 n=300000
Output for 5.3.13
time without regex: 0.44070196151733 n=300000 time with regex: 0.37759399414062 n=300000
Output for 5.3.12
time without regex: 0.4205219745636 n=300000 time with regex: 0.36322712898254 n=300000
Output for 5.3.11
time without regex: 0.42089605331421 n=300000 time with regex: 0.37076497077942 n=300000
Output for 5.3.10
time without regex: 0.41817688941956 n=300000 time with regex: 0.36798906326294 n=300000
Output for 5.3.9
time without regex: 0.4495370388031 n=300000 time with regex: 0.36541700363159 n=300000
Output for 5.3.8
time without regex: 0.40861105918884 n=300000 time with regex: 0.33839511871338 n=300000
Output for 5.3.7
time without regex: 0.43358397483826 n=300000 time with regex: 0.39420604705811 n=300000
Output for 5.3.6
time without regex: 0.43350887298584 n=300000 time with regex: 0.36204791069031 n=300000
Output for 5.3.5
time without regex: 0.41689300537109 n=300000 time with regex: 0.37922096252441 n=300000
Output for 5.3.4
time without regex: 0.40530896186829 n=300000 time with regex: 0.3601770401001 n=300000
Output for 5.3.3
time without regex: 0.44110488891602 n=300000 time with regex: 0.34979104995728 n=300000
Output for 5.3.2
time without regex: 0.39920902252197 n=300000 time with regex: 0.36995506286621 n=300000
Output for 5.3.1
time without regex: 0.3932888507843 n=300000 time with regex: 0.36571407318115 n=300000
Output for 5.3.0
time without regex: 0.41968011856079 n=300000 time with regex: 0.37977004051208 n=300000
Output for 5.2.17
time without regex: 0.5002920627594 n=300000 time with regex: 0.44174909591675 n=300000
Output for 5.2.16
time without regex: 0.52193307876587 n=300000 time with regex: 0.38279891014099 n=300000
Output for 5.2.15
time without regex: 0.51764416694641 n=300000 time with regex: 0.42761397361755 n=300000
Output for 5.2.14
time without regex: 0.55052185058594 n=300000 time with regex: 0.44281005859375 n=300000
Output for 5.2.13
time without regex: 0.49104189872742 n=300000 time with regex: 0.38361501693726 n=300000
Output for 5.2.12
time without regex: 0.49514818191528 n=300000 time with regex: 0.38032078742981 n=300000
Output for 5.2.11
time without regex: 0.51850509643555 n=300000 time with regex: 0.4326388835907 n=300000
Output for 5.2.10
time without regex: 0.55913209915161 n=300000 time with regex: 0.44434905052185 n=300000
Output for 5.2.9
time without regex: 0.48808312416077 n=300000 time with regex: 0.42646312713623 n=300000
Output for 5.2.8
time without regex: 0.49525380134583 n=300000 time with regex: 0.3674111366272 n=300000
Output for 5.2.7
time without regex: 0.48658394813538 n=300000 time with regex: 0.37953305244446 n=300000
Output for 5.2.6
time without regex: 0.49546003341675 n=300000 time with regex: 0.41002297401428 n=300000
Output for 5.2.5
time without regex: 0.54255986213684 n=300000 time with regex: 0.40520882606506 n=300000
Output for 5.2.4
time without regex: 0.51842212677002 n=300000 time with regex: 0.39688897132874 n=300000
Output for 5.2.3
time without regex: 0.50933694839478 n=300000 time with regex: 0.3901469707489 n=300000
Output for 5.2.2
time without regex: 0.51628088951111 n=300000 time with regex: 0.40990209579468 n=300000
Output for 5.2.1
time without regex: 0.53038501739502 n=300000 time with regex: 0.37293004989624 n=300000
Output for 5.2.0
time without regex: 0.60553193092346 n=300000 time with regex: 0.39829993247986 n=300000
Output for 5.1.6
time without regex: 0.57178282737732 n=300000 time with regex: 0.41626906394958 n=300000
Output for 5.1.5
time without regex: 0.53754496574402 n=300000 time with regex: 0.36681699752808 n=300000
Output for 5.1.4
time without regex: 0.5605640411377 n=300000 time with regex: 0.35952997207642 n=300000
Output for 5.1.3
time without regex: 0.52697205543518 n=300000 time with regex: 0.38502287864685 n=300000
Output for 5.1.2
time without regex: 0.59479308128357 n=300000 time with regex: 0.34682893753052 n=300000
Output for 5.1.1
time without regex: 0.55599784851074 n=300000 time with regex: 0.35654997825623 n=300000
Output for 5.1.0
time without regex: 0.57084393501282 n=300000 time with regex: 0.35300517082214 n=300000
Output for 5.0.5
time without regex: 0.98791813850403 n=300000 time with regex: 0.56770801544189 n=300000
Output for 5.0.4
time without regex: 0.95655202865601 n=300000 time with regex: 0.49562788009644 n=300000
Output for 5.0.3
time without regex: 0.90219688415527 n=300000 time with regex: 0.47799801826477 n=300000
Output for 5.0.2
time without regex: 0.86794686317444 n=300000 time with regex: 0.48481392860413 n=300000
Output for 5.0.1
time without regex: 0.88619494438171 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: 0.46982908248901 n=300000
Output for 5.0.0
time without regex: 1.1101720333099 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: 0.47431111335754 n=300000
Output for 4.4.9
time without regex: -0.139082 n=300000 time with regex: 0.45145 n=300000
Output for 4.4.8
time without regex: 0.831027 n=300000 time with regex: -0.541145 n=300000
Output for 4.4.7
time without regex: -0.148119 n=300000 time with regex: 0.485816 n=300000
Output for 4.4.6
time without regex: -0.115701 n=300000 time with regex: -0.481195 n=300000
Output for 4.4.5
time without regex: 0.843651 n=300000 time with regex: -0.540003 n=300000
Output for 4.4.4
time without regex: -0.119921 n=300000 time with regex: 0.496006 n=300000
Output for 4.4.3
time without regex: -0.163787 n=300000 time with regex: -0.543158 n=300000
Output for 4.4.2
time without regex: -0.185325 n=300000 time with regex: 0.474015 n=300000
Output for 4.4.1
time without regex: -0.185177 n=300000 time with regex: 0.474435 n=300000
Output for 4.4.0
time without regex: -0.147378 n=300000 time with regex: -0.496123 n=300000
Output for 4.3.11
time without regex: -0.166066 n=300000 time with regex: 0.455142 n=300000
Output for 4.3.10
time without regex: -0.171771 n=300000 time with regex: 0.467411 n=300000
Output for 4.3.9
time without regex: -0.095826 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.470829 n=300000
Output for 4.3.8
time without regex: 0.0989 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: 0.517783 n=300000
Output for 4.3.7
time without regex: -0.043641 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.458187 n=300000
Output for 4.3.6
time without regex: 0.17944 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.489763 n=300000
Output for 4.3.5
time without regex: -0.066665 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: 0.534724 n=300000
Output for 4.3.4
time without regex: 0.088874 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.436288 n=300000
Output for 4.3.3
time without regex: 0.026845 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.251248 n=300000
Output for 4.3.2
time without regex: -0.068293 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: 0.511019 n=300000
Output for 4.3.1
time without regex: -0.015822 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.507631 n=300000
Output for 4.3.0
time without regex: 0.43855 n=300000 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/BKhD4 on line 27 PHP_EOLtime with regex: -0.318416 n=300000