Good call! Using your exact same code and looping 1 million times, I pitted
eregi against
preg_match with the case insensitive switch set. I already have a sneaky feeling
preg_match is faster, but we shall see.
This will be based on the following simple code:
PHP Code:
$myString = 'TalkPHP.com';
for($i = 0; $i <= 1000000; $i++)
{
var_dump(preg_match('/^[A-Z\.]+$/i', $myString));
}
And:
PHP Code:
$myString = 'TalkPHP.com';
for($i = 0; $i <= 1000000; $i++)
{
var_dump(eregi('^[A-Z\.]+$', $myString));
}
Here are the results:
- eregi #1: 10.83 seconds
- eregi #2: 10.41 seconds
- eregi #3: 10.29 seconds
- preg_match #1: 10.42 seconds
- preg_match #2: 10.15 seconds
- preg_match #2: 10.06 seconds
Surprisingly, not a whole lot of difference. It may be that
preg_match has the advantage when complex regular expressions are being used.
preg_match is marginally faster than
eregi and I'll think I'll be sticking with it as my preference!