TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack (1) Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 12-12-2007, 07:49 AM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Jay
The Contributor
Good Samaritan 
 
Join Date: Dec 2007
Posts: 60
Thanks: 5
Jay is on a distinguished road
Default Quicker String Verification

I thought of a way to validate string length earlier today, and when I went to go benchmark it, it proved to be faster/more efficient than using strlen.

My method:
PHP Code:
// We want strings less than or equal to 32 characters
if( isset( $string[32] ) )
{
    
// Failed! This string is 33 characters! (arrays are 0 indexed, so 32 characters is index 31, and 33 is index 32!)

After ten-thousand iterations, it proved to only be 0.001500s, where as:

PHP Code:
if( strlen$string ) > 32 )
{
    
// Failed! This string is 33+ characters!

Took about 0.006000s

So as I see it, using my method proves to be very efficient (3x's faster than strlen). Any objections, comments, or complaints before I state this as a standard in my mind?
Jay is offline  
Reply With Quote
 


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/tips-tricks/1716-quicker-string-verification.html
Posted By For Type Date
TalkPHP - Powered by vBulletin This thread Refback 12-29-2007 10:17 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:55 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design