Created
April 24, 2012 08:32
-
-
Save rATRIJS/2477907 to your computer and use it in GitHub Desktop.
Some random regex vs strpos 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 | |
function test_valid_strpos($s) { foreach(array(';', ',', '|', '[', ']') as $c) if(false !== strpos($s, $c)) return false; return true; } | |
function test_valid_regex($s) { return preg_match('/[;,|\[\]]/', $s) === 0; } | |
function test_valid_strpbrk($s) { return false === strpbrk($s, ';,|[]'); } | |
function test_test_valid_strpos($s) { $t = microtime(true); for($i = 0; $i < 1000000; $i++) test_valid_strpos($s); return (microtime(true) - $t); } | |
function test_test_valid_regex($s) { $t = microtime(true); for($i = 0; $i < 1000000; $i++) test_valid_regex($s); return (microtime(true) - $t); } | |
function test_test_valid_strpbrk($s) { $t = microtime(true); for($i = 0; $i < 1000000; $i++) test_valid_strpbrk($s); return (microtime(true) - $t); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment