View Single Post
Old 09-29-2007, 06:55 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

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!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote