Hi All,
I have heard other people say that PHP can parse double quoted strings
(e.g., "Hello, World") faster than it can parse single quoted strings (e.g.,
'Hello, World'). This seems backwards to me, since double quote strings
have to be checked for any variables that need to be interpreted, whereas
single quoted strings do not.
So, what is the truth on this matter? And the explanation? Thanks for any
information!
-Josh 12 16423
Joshua Beall: Hi All,
I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards to me, since double quote strings have to be checked for any variables that need to be interpreted, whereas single quoted strings do not.
So, what is the truth on this matter? And the explanation? Thanks for any information!
The truth is as you think, double quoted strings require more work. But the
difference is absolutely negligible. I use single or double quotes
depending on the nature of the text, if it contains many double quotes,
like HTML often does, I prefer single quotes.
André Næss
Joshua Beall <jb****@donotsp am.remove.me.he raldic.us> wrote: I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards to me, since double quote strings have to be checked for any variables that need to be interpreted, whereas single quoted strings do not. http://www.phpfreaks.com/forums/inde...howtopic=13321 (a reliable
source) says that single quotes are prefereable.
--
Michael Wilcox
mjwilco at yahoo dot com
Essential Tools for the Web Developer - http://mikewilcox.t35.com
On 2004-01-24, Joshua Beall <jb****@donotsp am.remove.me.he raldic.us> wrote: Hi All,
I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards to me, since double quote strings have to be checked for any variables that need to be interpreted, whereas single quoted strings do not.
So, what is the truth on this matter? And the explanation? Thanks for any information!
Imho there is only one way to find out. experiment.
doublequotestim e = 0;
singlequotestim e = 0;
for 10000 times
get timestamp
for 1000000000 times
echo "hello world"
get timestamp2
doublequotestim e += (timestamp2 - timestamp)
get timestamp
for 1000000000 times
echo 'hello world'
get timestamp2
singlequotestim e += (timestamp2 - timestamp)
echo doublequotestim e;
echo singlequotestim e;
-- http://home.mysth.be/~timvw
Joshua Beall wrote: Hi All,
I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards to me, since double quote strings have to be checked for any variables that need to be interpreted, whereas single quoted strings do not.
So, what is the truth on this matter? And the explanation? Thanks for any information!
Strings enclosed in single quotes are taken literally, double quoted strings
are parsed by PHP:
$w = "World";
print "Hello $w"; // prints `Hello World`
print 'Hello $w'; // prints `Hello $w`
So in that sence, single quoted strings are faster and you're are right...
JW
In message <67************ ****@nwrddc03.g nilink.net>, Joshua Beall
<jb****@donotsp am.remove.me.he raldic.us> writes Hi All,
I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards to me, since double quote strings have to be checked for any variables that need to be interpreted, whereas single quoted strings do not.
So, what is the truth on this matter? And the explanation? Thanks for any information!
I heard the other way round, but have no idea just what kind of impact
it actually makes. My suspicion is that in the real world very little,
unless the server is almost at breaking point.
--
Five Cats
Email to: cats_spam at uk2 dot net
Tim Van Wassenhove wrote: Imho there is only one way to find out. experiment.
single quotes are marginally faster (as has been said in this thread
often enough)
#v+
<?php
$doubletime=0;
$singletime=0;
$doubleruns=0;
$singleruns=0;
$n=100000;
while (--$n) {
$double=true;
if (rand()%2) $double=false;
## start timing
$start = microtime();
## every time the script goes through here
## it will do two comparisons and one assignment
if ($double) $x="n=$n";
if (!$double) $x='n='.$n;
$finis=microtim e();
## end timing
## Is microtime()'s resolution accurate enough for this test? ????!?!?
if ($double) $doubletime+=ar ray_sum(explode (' ', $finis)) - array_sum(explo de(' ', $start));
else $singletime+=ar ray_sum(explode (' ', $finis)) - array_sum(explo de(' ', $start));
if ($double) ++$doubleruns;
else ++$singleruns;
}
$doubleperrun=$ doubletime/$doubleruns;
$singleperrun=$ singletime/$singleruns;
echo "singleperr un: $singleperrun (over $singleruns runs)\n";
echo "doubleperr un: $doubleperrun (over $doubleruns runs)\n\n";
?>
#v-
On my machine one run of this script produced:
singleperrun: 3.76346098519E-05 (over 49817 runs)
doubleperrun: 4.15038085678E-05 (over 50182 runs)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
:-)))
parsing single quoted strings is naturally FASTER, and not vice versa. If
you don't believe
just run a small test (5 lines script, timer on, loop, some evaluation, end
of loop, timer off, compare time). Then change the evaluation part and
compare the times again. (or just read something on iteration counting and
you will find out that it is not true what those people say, (unless php
coders intended it, what they naturally did NOT :-)))
Best Regards,
Lucas
"Joshua Beall" <jb****@donotsp am.remove.me.he raldic.us> schrieb im
Newsbeitrag news:67******** ********@nwrddc 03.gnilink.net. .. Hi All,
I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings
(e.g., 'Hello, World'). This seems backwards to me, since double quote strings have to be checked for any variables that need to be interpreted, whereas single quoted strings do not.
So, what is the truth on this matter? And the explanation? Thanks for
any information!
-Josh
On 2004-01-24, Pedro Graca <he****@hotpop. com> wrote: Tim Van Wassenhove wrote: Imho there is only one way to find out. experiment.
single quotes are marginally faster (as has been said in this thread often enough)
I wrote the post even after why ppl had explained which is the fastest
All i was trying to say to the OP: measure the differences, and see if
you think they are big enough to care about them. In most cases the
bottleneck is not in the difference between single and double quotes
anyway.
-- http://home.mysth.be/~timvw
Your test code has too much overhead. I ran the code listed below and the
loop with the single quoted string finishes in less than half the time the
double quoted one does.
Who cares about microsecond differences though. If you do, then consider
contracting the names of your functions to something like f1(). Calling
functions with longer names is slightly more costly.
function microtime_diff( $a, $b) {
list($a_dec, $a_sec) = explode(" ", $a);
list($b_dec, $b_sec) = explode(" ", $b);
return $b_sec - $a_sec + $b_dec - $a_dec;
}
$something = "Cow";
$start_time_1 = microtime();
for($i = 0; $i < 1000000; $i++) {
$s = "This is $something else";
}
$duration_1 = microtime_diff( $start_time_1, microtime());
$start_time_2 = microtime();
for($i = 0; $i < 1000000; $i++) {
$s = 'This is ' . $something . 'else';
}
$duration_2 = microtime_diff( $start_time_2, microtime());
echo "$duration_ 1 vs. $duration_2";
Uzytkownik "Pedro Graca" <he****@hotpop. com> napisal w wiadomosci
news:bu******** ****@ID-203069.news.uni-berlin.de... Tim Van Wassenhove wrote: Imho there is only one way to find out. experiment. single quotes are marginally faster (as has been said in this thread often enough)
#v+ <?php $doubletime=0; $singletime=0; $doubleruns=0; $singleruns=0;
$n=100000; while (--$n) { $double=true; if (rand()%2) $double=false;
## start timing $start = microtime(); ## every time the script goes through here ## it will do two comparisons and one assignment if ($double) $x="n=$n"; if (!$double) $x='n='.$n; $finis=microtim e(); ## end timing
## Is microtime()'s resolution accurate enough for this test? ????!?!?
if ($double) $doubletime+=ar ray_sum(explode (' ', $finis)) -
array_sum(explo de(' ', $start)); else $singletime+=ar ray_sum(explode (' ', $finis)) -
array_sum(explo de(' ', $start)); if ($double) ++$doubleruns; else ++$singleruns; } $doubleperrun=$ doubletime/$doubleruns; $singleperrun=$ singletime/$singleruns;
echo "singleperr un: $singleperrun (over $singleruns runs)\n"; echo "doubleperr un: $doubleperrun (over $doubleruns runs)\n\n"; ?> #v-
On my machine one run of this script produced: singleperrun: 3.76346098519E-05 (over 49817 runs) doubleperrun: 4.15038085678E-05 (over 50182 runs) -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Simon Bunker |
last post by:
I was just wondering why python doesn't make a distinction between single
and double
quotes - a bit like Perl does.
Obviously I realise there are no dollar signs so you can't intrpolate a
varaible in a string.
This is fine, but having to remember to put an r in front of regex's is
really annoying and it would
be great if you could jsut use single quotes instead to interpolate slashes
properly etc. (ie only escape them once).
|
by: Thomas Miskiewicz |
last post by:
Hi!
Is using of a double quotation mark with a URL a problem? For example:
http://myserver.com/query?field1=something&field2=test¶ms="field1=test1"+"field2=test2"
Regards
Thomas
|
by: David Bird |
last post by:
I am attempting to build a command string to update a field in a dataset.
the command string looks like this:
Dim cmdString As String = "Update set lName = '" & clName.Trim
& "', fName = '" & cfName.Trim & "' Where id = " & lnID
the command works fine unless and until clname and/or cfname contains an
apostrophe, ie: O'Hare
When the executeNonquery is run, the quotes are out of balance and a syntax
error is thrown.
|
by: Greg |
last post by:
I keep getting an error when I have a tick mark in a text value that I am
searching for in my XPath Query.
Example:
<Authors>
<Author LastName="O'Donnel">
<Author LastName="Smith">
</Authors>
|
by: gar |
last post by:
Hi,
I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code
text= Replace(text, """", "'"
This works fine (for normal double quotes).The problem comes in when you copy a double quote from MS Word and paste it in the text box. What happens is the double quote becomes slanted (“) so my code above can't filter it. I tried to do this
text= Replace(text, "““","'")
| |
by: Dustin |
last post by:
I have a nested quotes issue I'm trying to resolve. Basically I need a 5th
level nested quote for quoting the string argument to the getXMLFeed()
function in the following:
var myHTML = "<TR onMouseOver='return overlib(\"<A
HREF=\'javascript:void(0)\'
onClick=\'javascript:getXMLFeed(\"price\")\'>Price</A>\"'>";
How do you do a 5th level nested quote?
|
by: Marina Levit [MVP] |
last post by:
I've scoured google, but apparently none of the suggestions actually work.
I have the following. type of XPATH query
"SomeNode[SomeAttribute = 'abc's search'"
Now, I've tried doing this:
"SomeNode[SomeAttribute = 'abc@apos;s search'"
|
by: fniles |
last post by:
I am looping thru DataReader and constructing a sql query to insert to
another database.
When the data type of the field is string I insert the field value using a
single quote.
When the value of the field has a single quote in it like "O'Toole", how can
I construct the string ?
Do While drSQL.Read
sSQL = "insert into " & sTableName & " values ("
sSQL2 = ""
|
by: U Aye Thein |
last post by:
I found in internet how to solve single quotation mark in string and how to solve double quotation mark in string but my string may be contained single quote or double quote. How to write an expression for my string test.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |