RE: FW: [PHP] Accessing a Char in an Array
| From: | Justin Palmer | Date: | Wed, 22 Dec 2004 04:57:49 +0000 |
| Subject: | RE: FW: [PHP] Accessing a Char in an Array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204937@lists.php.net to get a copy of this message | ||
Why is substr all over the board in how fast it processes the same
string? Is it the server?
Kind regards,
Justin
> -----Original Message-----
> From: Robert Cummings [mailto:robert@interjinn.com]
> Sent: Tuesday, December 21, 2004 8:58 PM
> To: justin.php.gen@jepaonline.com
> Cc: PHP-General; 'Curt Zirzow'
> Subject: Re: FW: [PHP] Accessing a Char in an Array
>
>
> On Tue, 2004-12-21 at 23:47, Justin Palmer wrote:
> > *Sorry Curt for sending this to you.*
> >
> > Hi,
> >
> > Well if any one is interested in the speed I set up an example that
> > you can go to. Though, when I run the example substr() is very
> > neurotic (or it seems that it is to me). It can process the
> same line
> > of code at a lot of different intervals, while accessing it
> with {} is
> > pretty consistant.
> >
> > What is the cause of this?
> >
> > I thought it might be the server, but would that not effect it for
> > both tests (two others tests with objects)?
> >
> > By the by, during my testing I found that using {} to
> access the first
> > char in a string was anywhere from .5 to 4 times faster.
>
> {} is an operator whereas substr() is a function. Operators
> are generally an order of magnitude faster than functions and
> if all you want is the first character then {0} is much more
> efficient than substr().
>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting | a
> | powerful, scalable system for accessing system services | such as
> | forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `------------------------------------------------------------'
>
>