Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 27
  1. #1
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    I have to check and see if a given string ends with another given string, case-insensitively...12,154,376 times. My current method takes far too long:
    PHP Code:
    $end substr($emailstrlen($email) - strlen($domain));
    $shady = (strcasecmp($end$domain) != 0);
    $shadies[$userid] = $shady
    Who can do it faster? The preg functions, naturally, did not help. The idea is to check if $email ends with $domain.
    (hint: this will be a WDF feature soon if it ever works anywhere near efficiently)
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    How about this:

    PHP Code:
    if(!eregi($domain."$"$email))
            
    $shadies[$userid] = false;
    else
            
    $shadies[$userid] = true
    There and Back Again :Ogre:

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    That's far slower, actually.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    eregi or the if statement?
    There and Back Again :Ogre:

  6. #5
    Dan
    Dan is offline
    Member
    Join Date
    Feb 2003
    Posts
    39
    Member #
    707
    $a = explode('@',$email);
    $b = ($a[1] == $a[2]) ? 'Success.' : 'Failure.';
    echo $b;

    Go ahead, shoot me.

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    That's signficantly faster than nsr81's and about the same as mine, although remember, it must be case-insensitive. Adding a line for strcasecomp slowed it down signficantly.

    Keep 'em coming, though.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  8. #7
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    BTW, to keep reliable benchmarks...this is Dan's above with strcasecomp:
    Code:
    Finished user 0 (0.28 msec so far)...
    Finished user 10 (2.67 msec so far)...
    Finished user 20 (5.03 msec so far)...
    Finished user 30 (7.37 msec so far)...
    Finished user 40 (9.72 msec so far)...
    This is nsr81's:
    Code:
    Finished user 0 (2.48 msec so far)...
    Finished user 10 (4.8 msec so far)...
    Finished user 20 (7.15 msec so far)...
    Finished user 30 (9.3 msec so far)...
    This is mine:
    Code:
    Finished user 0 (0.18 msec so far)...
    Finished user 10 (1.62 msec so far)...
    Finished user 20 (3.09 msec so far)...
    Finished user 30 (4.52 msec so far)...
    Finished user 40 (5.98 msec so far)...
    Finished user 50 (7.41 msec so far)...
    Finished user 60 (8.84 msec so far)...
    (I set PHP to time out after 10 seconds)
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  9. #8
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    ouch lol
    There and Back Again :Ogre:

  10. #9
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Why not process this in MySQL? It would probably execute 100 times faster.

  11. #10
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Because it would be one huge query...I'm not even sure if MySQL would support its length.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!


Page 1 of 3 1 2 3 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:48 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com