Skip to content

Instantly share code, notes, and snippets.

@rATRIJS
Created April 24, 2012 08:32
Show Gist options
  • Save rATRIJS/2477907 to your computer and use it in GitHub Desktop.
Save rATRIJS/2477907 to your computer and use it in GitHub Desktop.
Some random regex vs strpos test
<?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