Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

bind-address mysql multiple, sanibleone xxxx, ftp://192.168.100.100/, www.xxxcon, which comes first ob_start or session, wwwxxx/58/2010, xxxxdup, xxxxdup, mailx informatii, should producers of software-based services, such as atms, be held liable for economic injuries suffered when their systems fail?

Links

XODOX
Impressum

#1: which one is faster

Posted on 2010-10-05 21:23:32 by saeed ahmed

--0016e64805a8b303190491e39899
Content-Type: text/plain; charset=UTF-8

$a = 'hey';
$b = 'done';

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

which one is faster for echo $c.

--0016e64805a8b303190491e39899--

Report this message

#2: Re: which one is faster

Posted on 2010-10-05 21:28:17 by Chris H

--001485e3ad3cb40afc0491e3a9d1
Content-Type: text/plain; charset=ISO-8859-1

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@gmail.com> wrote:

> $a = 'hey';
> $b = 'done';
>
> $c = $a.$b;
> $c = "$a$b";
>
> which one is faster for echo $c.
>

--001485e3ad3cb40afc0491e3a9d1--

Report this message

#3: Re: which one is faster

Posted on 2010-10-05 21:35:48 by Ashley Sheridan

--=-meBEdqYvpDOTTvkf3j5v
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

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@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



--=-meBEdqYvpDOTTvkf3j5v--

Report this message

#4: Re: which one is faster

Posted on 2010-10-05 21:43:34 by Chris H

--0016363b88005c58ed0491e3e054
Content-Type: text/plain; charset=ISO-8859-1

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@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@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
>
>
>

--0016363b88005c58ed0491e3e054--

Report this message

#5: Re: which one is faster

Posted on 2010-10-05 21:46:13 by Steven Staples

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@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.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#6: Re: which one is faster

Posted on 2010-10-05 21:53:03 by Ashley Sheridan

--=-0EgJbHgMGpRGmxfHhuzD
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:

> 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@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.
>
>


It doesn't have to use the braces. The braces only tell PHP exactly
where to stop parsing the current variable name. The following examples
wouldn't work without them:

$var = 'hello ';
$arr = array('msg 1'=>'hello','msg 2'=>'world');

echo "{$var}world";
echo "{$arr['msg 1']}{$arr['msg 2']}";

Without the braces, in the first example PHP would look for a variable
called $varworld, and in the second it would be looking for a simple
scaler called $arr, not the array value you wanted.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-0EgJbHgMGpRGmxfHhuzD--

Report this message

#7: Re: which one is faster

Posted on 2010-10-05 21:54:03 by TR Shaw

On Oct 5, 2010, at 3:23 PM, saeed ahmed wrote:

> $a = 'hey';
> $b = 'done';
>
> $c = $a.$b;
> $c = "$a$b";
>
> which one is faster for echo $c.

Depends upon the platform its running on.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#8: Re: which one is faster

Posted on 2010-10-05 21:56:25 by Chris H

--0050450159cf4fc8930491e40ed9
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Oct 5, 2010 at 3:53 PM, Ashley Sheridan <ash@ashleysheridan.co.uk>wrote:

> On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:
>
> > 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@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.
> >
> >
>
>
> It doesn't have to use the braces. The braces only tell PHP exactly
> where to stop parsing the current variable name. The following examples
> wouldn't work without them:
>
> $var = 'hello ';
> $arr = array('msg 1'=>'hello','msg 2'=>'world');
>
> echo "{$var}world";
> echo "{$arr['msg 1']}{$arr['msg 2']}";
>
> Without the braces, in the first example PHP would look for a variable
> called $varworld, and in the second it would be looking for a simple
> scaler called $arr, not the array value you wanted.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
Just to add in here, they are also required when calling an object's
properties, if - ready for this? - that object is itself a property of
another object.

so while this would work,

"$circle->circumference"

this would NOT work

"$circle->circumference->inches"

The later would be injecting the $circle->circumference property, followed
by string literal "->inches". So to get it to work you would need to use
curlys.

"{$circle->circumference->inches}"


Chris H.

--0050450159cf4fc8930491e40ed9--

Report this message

#9: Re: which one is faster

Posted on 2010-10-05 21:58:47 by Steven Staples

On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
> On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:
>
> > 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@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.
> >
> >
>
>
> It doesn't have to use the braces. The braces only tell PHP exactly
> where to stop parsing the current variable name. The following examples
> wouldn't work without them:
>
> $var = 'hello ';
> $arr = array('msg 1'=>'hello','msg 2'=>'world');
>
> echo "{$var}world";
> echo "{$arr['msg 1']}{$arr['msg 2']}";
>
> Without the braces, in the first example PHP would look for a variable
> called $varworld, and in the second it would be looking for a simple
> scaler called $arr, not the array value you wanted.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
Ash:

I understand what the {} does, but just like in HTML, it is more proper
to use lower case for the attributes/elements, and use " (double quotes)
when wrapping the attributes... but is it not "REQUIRED" to write it in
that manner... just like it is not required to wrap the variables in {}
when inside the ""...

that's just me, I tend to try and do that every time...

Steve.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#10: Re: which one is faster

Posted on 2010-10-05 22:06:08 by Ashley Sheridan

--=-qOmGFhzrTQCReSqUuQV5
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

On Tue, 2010-10-05 at 15:58 -0400, Steve Staples wrote:

> On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
> > On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:
> >
> > > 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@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.
> > >
> > >
> >
> >
> > It doesn't have to use the braces. The braces only tell PHP exactly
> > where to stop parsing the current variable name. The following examples
> > wouldn't work without them:
> >
> > $var = 'hello ';
> > $arr = array('msg 1'=>'hello','msg 2'=>'world');
> >
> > echo "{$var}world";
> > echo "{$arr['msg 1']}{$arr['msg 2']}";
> >
> > Without the braces, in the first example PHP would look for a variable
> > called $varworld, and in the second it would be looking for a simple
> > scaler called $arr, not the array value you wanted.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> Ash:
>
> I understand what the {} does, but just like in HTML, it is more proper
> to use lower case for the attributes/elements, and use " (double quotes)
> when wrapping the attributes... but is it not "REQUIRED" to write it in
> that manner... just like it is not required to wrap the variables in {}
> when inside the ""...
>
> that's just me, I tend to try and do that every time...
>
> Steve.
>
>


Not really, it's no more proper than the difference between:

echo 'text' . $var;
or
echo "text$var";

And in some cases, it is required. It is down to preference if you use
them when you don't have to, but personally I'd avoid typing what is
essentially useless fluff.


Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-qOmGFhzrTQCReSqUuQV5--

Report this message

#11: Re: which one is faster

Posted on 2010-10-05 22:08:54 by Chris H

--0022152d6dddf80a0f0491e43ab7
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Oct 5, 2010 at 3:58 PM, Steve Staples <sstaples@mnsi.net> wrote:

> On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
> > On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:
> >
> > > 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@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.
> > >
> > >
> >
> >
> > It doesn't have to use the braces. The braces only tell PHP exactly
> > where to stop parsing the current variable name. The following examples
> > wouldn't work without them:
> >
> > $var = 'hello ';
> > $arr = array('msg 1'=>'hello','msg 2'=>'world');
> >
> > echo "{$var}world";
> > echo "{$arr['msg 1']}{$arr['msg 2']}";
> >
> > Without the braces, in the first example PHP would look for a variable
> > called $varworld, and in the second it would be looking for a simple
> > scaler called $arr, not the array value you wanted.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> Ash:
>
> I understand what the {} does, but just like in HTML, it is more proper
> to use lower case for the attributes/elements, and use " (double quotes)
> when wrapping the attributes... but is it not "REQUIRED" to write it in
> that manner... just like it is not required to wrap the variables in {}
> when inside the ""...
>
> that's just me, I tend to try and do that every time...
>
> Steve.
>
>

Unlike HTML, PHP interpretation doesn't have various browsers to contend
with. And even if it was not proper I have a doubt that not using {} would
become deprecated anytime soon.

Also laziness is a trait of a good programmer! :)
http://c2.com/cgi/wiki?LazinessImpatienceHubris

Chris H.

--0022152d6dddf80a0f0491e43ab7--

Report this message

#12: Re: which one is faster

Posted on 2010-10-05 22:09:00 by joao

As I can see, it´d be too much faster to decide by yourself than reading all
theese answers and understanding their differences and taking people´s time
for nothing.

--
João Cândido de Souza Neto

"saeed ahmed" <saeed.sas@gmail.com> escreveu na mensagem
news:AANLkTikh6g5iLSz3HKxaTg=H1wzoBGoKo7bYNGo0pOdy@mail.gmai l.com...
> $a = 'hey';
> $b = 'done';
>
> $c = $a.$b;
> $c = "$a$b";
>
> which one is faster for echo $c.
>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#13: RE: which one is faster

Posted on 2010-10-06 14:40:16 by Bob McConnell

From: Steve Staples

> On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
>> On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:
>>=20
>> > On Tue, 2010-10-05 at 20:35 +0100, Ashley Sheridan wrote:
>> > > On Tue, 2010-10-05 at 15:28 -0400, chris h wrote:
>> > >=20
>> > > > Benchmark and find out! :)
>> > > >=20
>> > > > 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.
>> > > >=20
>> > > > Chris H.
>> > > >=20
>> > > > On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed
<saeed.sas@gmail.com> wrote:
>> > > >=20
>> > > > > $a =3D 'hey';
>> > > > > $b =3D 'done';
>> > > > >
>> > > > > $c =3D $a.$b;
>> > > > > $c =3D "$a$b";
>> > > > >
>> > > > > which one is faster for echo $c.
>> > > > >
>> > >=20
>> > >=20
>> > > 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
>> >=20
>> > to be proper, shouldn't it technically be
>> > $c =3D "{$a}{$b}";
>> >=20
>>=20
>> It doesn't have to use the braces. The braces only tell PHP exactly
>> where to stop parsing the current variable name. The following
examples
>> wouldn't work without them:
>>=20
>> $var =3D 'hello ';
>> $arr =3D array('msg 1'=3D>'hello','msg 2'=3D>'world');
>>=20
>> echo "{$var}world";
>> echo "{$arr['msg 1']}{$arr['msg 2']}";
>>=20
>> Without the braces, in the first example PHP would look for a
variable
>> called $varworld, and in the second it would be looking for a simple
>> scaler called $arr, not the array value you wanted.
>>=20
> Ash:
>=20
> I understand what the {} does, but just like in HTML, it is more
proper
> to use lower case for the attributes/elements, and use " (double
quotes)
> when wrapping the attributes... but is it not "REQUIRED" to write it
in
> that manner... just like it is not required to wrap the variables in
{}
> when inside the ""...=20
>=20
> that's just me, I tend to try and do that every time...=20

XHTML requires both lower case and double quotes. So if that may be in
your future, you should be using both already.

I don't know about HTML 5. Since that spec is still years away from
completion and hasn't added anything we can make use of, we haven't even
bothered to look at it.

Bob McConnell

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#14: Re: which one is faster

Posted on 2010-10-06 14:52:14 by Peter Lind

On 6 October 2010 14:40, Bob McConnell <rvm@cbord.com> wrote:
> From: Steve Staples
>
>> On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
>>> On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:
>>>
>>> > 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@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}";
>>> >
>>>
>>> It doesn't have to use the braces. The braces only tell PHP exactly
>>> where to stop parsing the current variable name. The following
> examples
>>> wouldn't work without them:
>>>
>>> $var = 'hello ';
>>> $arr = array('msg 1'=>'hello','msg 2'=>'world');
>>>
>>> echo "{$var}world";
>>> echo "{$arr['msg 1']}{$arr['msg 2']}";
>>>
>>> Without the braces, in the first example PHP would look for a
> variable
>>> called $varworld, and in the second it would be looking for a simple
>>> scaler called $arr, not the array value you wanted.
>>>
>> Ash:
>>
>> I understand what the {} does, but just like in HTML, it is more
> proper
>> to use lower case for the attributes/elements, and use " (double
> quotes)
>> when wrapping the attributes... but is it not "REQUIRED" to write it
> in
>> that manner... just like it is not required to wrap the variables in
> {}
>> when inside the ""...
>>
>> that's just me, I tend to try and do that every time...
>
> XHTML requires both lower case and double quotes. So if that may be in
> your future, you should be using both already.
>
> I don't know about HTML 5. Since that spec is still years away from
> completion and hasn't added anything we can make use of, we haven't even
> bothered to look at it.
>

Where exactly do you get the part about double quotes from? Can't seem
to locate it in the any of the relevant specs (xhtml or xml). Also,
never seen an xml or xhtml validator choke on single quotes.

As for html 5, it's in use today already. Big parts of it are unlikely
to change, so there's little reason not to start using it.

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#15: Re: which one is faster

Posted on 2010-10-06 15:03:07 by Robert Cummings

On 10-10-06 08:52 AM, Peter Lind wrote:
> Where exactly do you get the part about double quotes from? Can't seem
> to locate it in the any of the relevant specs (xhtml or xml). Also,
> never seen an xml or xhtml validator choke on single quotes.

http://www.w3.org/TR/xhtml1/#h-4.2

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#16: Re: which one is faster

Posted on 2010-10-06 15:10:07 by Robert Cummings

On 10-10-06 09:06 AM, Peter Lind wrote:
> On 6 October 2010 15:03, Robert Cummings<robert@interjinn.com> wrote:
>> On 10-10-06 08:52 AM, Peter Lind wrote:
>>>
>>> Where exactly do you get the part about double quotes from? Can't seem
>>> to locate it in the any of the relevant specs (xhtml or xml). Also,
>>> never seen an xml or xhtml validator choke on single quotes.
>>
>> http://www.w3.org/TR/xhtml1/#h-4.2
>>
>
> I quote: "4.2. Element and attribute names must be in lower case.
> XHTML documents must use lower case for all HTML element and attribute
> names. This difference is necessary because XML is case-sensitive e.g.
> <li> and<LI> are different tags."
>
> Where in that do you see anything about double quotes?
>
> Maybe you're thinking of http://www.w3.org/TR/xhtml1/#h-4.4 - but that
> just states quoted, nothing about double quotes vs. single quotes.

Nope, sorry, I had lowercase on the brain. In XHTML you can use single
or double quotes :)

*gulps down more coffee*

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#17: Re: which one is faster

Posted on 2010-10-06 15:21:41 by Andy McKenzie

On Wed, Oct 6, 2010 at 9:03 AM, Robert Cummings <robert@interjinn.com> wrote:
> On 10-10-06 08:52 AM, Peter Lind wrote:
>>
>> Where exactly do you get the part about double quotes from? Can't seem
>> to locate it in the any of the relevant specs (xhtml or xml). Also,
>> never seen an xml or xhtml validator choke on single quotes.
>
> http://www.w3.org/TR/xhtml1/#h-4.2
>
> Cheers,
> Rob.

I don't see that it explicitly states a requirement for double quotes
there -- it certainly implies it, but the text never says anything
about either double-quotes being required or single-quotes being
disallowed.

Full text: "All attribute values must be quoted, even those which
appear to be numeric."

Is there a statement somewhere in the document that says quotes are
always double-quotes?

-Alex

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#18: Re: which one is faster

Posted on 2010-10-06 15:31:24 by Andy McKenzie

On Wed, Oct 6, 2010 at 9:25 AM, Peter Lind <peter.e.lind@gmail.com> wrote:
> On 6 October 2010 15:21, Andy McKenzie <amckenzie4@gmail.com> wrote:
>> On Wed, Oct 6, 2010 at 9:03 AM, Robert Cummings <robert@interjinn.com> w=
rote:
>>> On 10-10-06 08:52 AM, Peter Lind wrote:
>>>>
>>>> Where exactly do you get the part about double quotes from? Can't seem
>>>> to locate it in the any of the relevant specs (xhtml or xml). Also,
>>>> never seen an xml or xhtml validator choke on single quotes.
>>>
>>> http://www.w3.org/TR/xhtml1/#h-4.2
>>>
>>> Cheers,
>>> Rob.
>>
>> I don't see that it explicitly states a requirement for double quotes
>> there -- it certainly implies it, but the text never says anything
>> about either double-quotes being required or single-quotes being
>> disallowed.
>>
>> Full text: =A0"All attribute values must be quoted, even those which
>> appear to be numeric."
>>
>> Is there a statement somewhere in the document that says quotes are
>> always double-quotes?
>
> No, there isn't. Both single quotes and double quotes are allowed for
> attributes in both XML and XHTML. What makes you think it's implied
> that double quotes are the only allowed form of quotes?
>
> Regards
> Peter
>

Double quotes are the only example given: in most documentation if
there are two allowed forms, there are two examples, or at least a
note in the text. I haven't read enough of this particular document
to know if they follow that form, but I've certainly seen it a lot of
places.

-Alex

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#19: Re: which one is faster

Posted on 2010-10-06 15:43:08 by Peter Lind

On 6 October 2010 15:31, Andy McKenzie <amckenzie4@gmail.com> wrote:

*snip*

> Double quotes are the only example given: àin most documentation if
> there are two allowed forms, there are two examples, or at least a
> note in the text. àI haven't read enough of this particular document
> to know if they follow that form, but I've certainly seen it a lot of
> places.
>
> -Alex
>

Xhtml documents are xml documents and thus must follow the specs for
XML. Specifically, the following:
http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue

Regards
Peter

--=20
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#20: Re: which one is faster

Posted on 2010-10-06 16:00:19 by Steven Staples

On Wed, 2010-10-06 at 15:43 +0200, Peter Lind wrote:
> On 6 October 2010 15:31, Andy McKenzie <amckenzie4@gmail.com> wrote:
>
> *snip*
>
> > Double quotes are the only example given: in most documentation if
> > there are two allowed forms, there are two examples, or at least a
> > note in the text. I haven't read enough of this particular document
> > to know if they follow that form, but I've certainly seen it a lot of
> > places.
> >
> > -Alex
> >
>
> Xhtml documents are xml documents and thus must follow the specs for
> XML. Specifically, the following:
> http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
>
> Regards
> Peter

Wow... I didn't mean to spark up a debate/battle about the use of " vs '
or anything... I was just under the impression that the use of {} when
referring to a variable inside the "" was "proper", and was the way it
"should" be done, not that it "HAD" to be done that way... even back
in 92 when I started HTML programming, I was taught that elements and
attributes should be in lower case, attributes should be within ""...
and when i started using PHP, I would always use "" and when referencing
a variable, "text ". $var ." more text" was the way I did it, and then i
read somewhere that variable inside "" to avoid any potential issues,
should be enclosed with {}. Granted, it works without using them (for
99% of things), but as my personal preference, that is the way i do it,
and was under the impression that it should be used in that manner, to
avoid deprecation.

Now, to end my run on and on and on sentence... it was just something I
have always done, just like the code formatting i follow (which i wont
get into, cuz that will prolly start another huge long thread too :P)
--

As for the OP's question, I don't think it really matters which one you
use, it would boil down to which one makes more sense to you when you
read it later and try to figure out why you did it the way you did :)
(documentation is essential for deciphering code the next day)

If you're worried about I/O processes, and have to constrain yourself to
using 1 or 2 more I/O processes, then you should do a lot of
benchmarking to determine for yourself which is more efficient on your
hardware.

again, just my $0.02.


Steve.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#21: Re: which one is faster

Posted on 2010-10-08 18:16:56 by Nathan Rixham

chris h wrote:
> 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) );

that's not a fair test because you have rand() and md5() calls in there
(something temporally varying)

Here's a quick test script which does 100 million iterations on both, 3
times to get some half measurable results

$i = $its = 100000000;
$tests = 3;
$a = 'foo';
$b = 'bar';

while($tests-->0) {
$t = microtime(true);
while($i-->0) {
$c = "$a$b";
}
echo 'time .: ' . (microtime(true)-$t) . PHP_EOL;
$i = $its;
$t = microtime(true);
while($i-->0) {
$c = $a.$b;
}
echo 'time ": ' . (microtime(true)-$t) . PHP_EOL;
}

I also ran the tests in the opposite order just to ensure they were
fair, results are that $a.$b (concatenation) averaged 22 seconds, and
the "$a$b" approach was 28 seconds.

Thus, concatenation is faster - but you have to get up to circa 10
million+ uses per second to use it.

Best,

Nathan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message