From: saeed ahmed on
$a = 'hey';
$b = 'done';

$c = $a.$b;
$c = "$a$b";

which one is faster for echo $c.
From: chris h on
Benchmark and find out! :)

What are you using this for? Unless you are doing something crazy it
probably doesn't matter, and you should pick whichever you feel looks nicer
/ is easier to code in / etc.

Chris H.

On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed <saeed.sas(a)gmail.com> wrote:

> $a = 'hey';
> $b = 'done';
>
> $c = $a.$b;
> $c = "$a$b";
>
> which one is faster for echo $c.
>
From: Ashley Sheridan on
On Tue, 2010-10-05 at 15:28 -0400, chris h wrote:

> Benchmark and find out! :)
>
> What are you using this for? Unless you are doing something crazy it
> probably doesn't matter, and you should pick whichever you feel looks nicer
> / is easier to code in / etc.
>
> Chris H.
>
> On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed <saeed.sas(a)gmail.com> wrote:
>
> > $a = 'hey';
> > $b = 'done';
> >
> > $c = $a.$b;
> > $c = "$a$b";
> >
> > which one is faster for echo $c.
> >


As far as I'm aware, the first of the two will be faster, but only just.
As Saeed mentioned, the difference will be negligible, and unless you
plan to run a line like that in a loop or something hundreds of
thousands of times, you probably won't notice any difference.
Thanks,
Ash
http://www.ashleysheridan.co.uk


From: chris h on
Saeed here's a quick (and dirty) test I ran:


$tests = 1000000;

$start = microtime(true);
for ($i=0; $i<$tests; $i++) {

$a = md5( rand() );
$b = md5( rand() );

$c = $a.$b;
}
var_dump( "By concat op:\t". (microtime(true) - $start) );


$start = microtime(true);
for ($i=0; $i<$tests; $i++) {

$a = md5( rand() );
$b = md5( rand() );

$c = "$a$b";
}
var_dump( "By string:\t\t". (microtime(true) - $start) );


Sample results:
string(30) "By concat op: 2.1713118553162"
string(27) "By string: 2.2525599002838"

string(30) "By concat op: 2.2123351097107"
string(27) "By string: 2.2798750400543"

string(29) "By concat op: 2.1521489620209"
string(27) "By string: 2.2470209598541"

string(29) "By concat op: 2.1347990036011"
string(27) "By string: 2.1982681751251"


I would say that under virtually all cases that difference is less
then negligible.

Chris H.

On Tue, Oct 5, 2010 at 3:35 PM, Ashley Sheridan <ash(a)ashleysheridan.co.uk>wrote:

> On Tue, 2010-10-05 at 15:28 -0400, chris h wrote:
>
> Benchmark and find out! :)
>
> What are you using this for? Unless you are doing something crazy it
> probably doesn't matter, and you should pick whichever you feel looks nicer
> / is easier to code in / etc.
>
> Chris H.
>
> On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed <saeed.sas(a)gmail.com> wrote:
>
> > $a = 'hey';
> > $b = 'done';
> >
> > $c = $a.$b;
> > $c = "$a$b";
> >
> > which one is faster for echo $c.
> >
>
>
> As far as I'm aware, the first of the two will be faster, but only just. As
> Saeed mentioned, the difference will be negligible, and unless you plan to
> run a line like that in a loop or something hundreds of thousands of times,
> you probably won't notice any difference.
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
From: Steve Staples on
On Tue, 2010-10-05 at 20:35 +0100, Ashley Sheridan wrote:
> On Tue, 2010-10-05 at 15:28 -0400, chris h wrote:
>
> > Benchmark and find out! :)
> >
> > What are you using this for? Unless you are doing something crazy it
> > probably doesn't matter, and you should pick whichever you feel looks nicer
> > / is easier to code in / etc.
> >
> > Chris H.
> >
> > On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed <saeed.sas(a)gmail.com> wrote:
> >
> > > $a = 'hey';
> > > $b = 'done';
> > >
> > > $c = $a.$b;
> > > $c = "$a$b";
> > >
> > > which one is faster for echo $c.
> > >
>
>
> As far as I'm aware, the first of the two will be faster, but only just.
> As Saeed mentioned, the difference will be negligible, and unless you
> plan to run a line like that in a loop or something hundreds of
> thousands of times, you probably won't notice any difference.
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>


to be proper, shouldn't it technically be
$c = "{$a}{$b}";

??

Steve.