473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Performance impact about unquoted strings

I asked this question on php.general, but I didn't get any reply. So
I'm asking here now.

As you already know, when an identifier is not found to be a defined
constant, php interprets it as a string.

For example:
<?
$var=hello ;
?>

the "constant" hello is not defined, so $var takes the value "hello".

My question is the following:

I have a large script with several thousands of strings.
In order to reduce the files size, I removed all the quotes from the
strings.

What is the performance impact of this in terms of cpu-time and system
resources required??

I mean, the script will take longer to execute??
will it take more cpu??

Thanks in advance.

Sep 13 '06 #1
3 1652
He*************@gmail.com wrote:
I asked this question on php.general, but I didn't get any reply. So
I'm asking here now.

As you already know, when an identifier is not found to be a defined
constant, php interprets it as a string.

For example:
<?
$var=hello ;
?>

the "constant" hello is not defined, so $var takes the value "hello".

My question is the following:

I have a large script with several thousands of strings.
In order to reduce the files size, I removed all the quotes from the
strings.

What is the performance impact of this in terms of cpu-time and system
resources required??

I mean, the script will take longer to execute??
will it take more cpu??

Thanks in advance.
Yes, it will take longer to execute and require more CPU. Rather than
just accept the value as a string, the parser has to search through
defined values to see if each string is defined or not. Additionally,
PHP generates a notification for each one. The notification itself can
be turned off, but the error handler still needs to run to find out the
notification is not to be sent.

Additionally, there is no guarantee it will work in future versions of PHP.

Put them back in. Not having them is just sloppy programming. And a
few hundred bytes are not going to make much difference.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 13 '06 #2
Jerry Stuckle wrote:
Yes, it will take longer to execute and require more CPU. Rather than
just accept the value as a string, the parser has to search through
defined values to see if each string is defined or not. Additionally,
PHP generates a notification for each one. The notification itself can
be turned off, but the error handler still needs to run to find out the
notification is not to be sent.
To be a little more precise, PHP would perform two look-ups in the
constant hash-table: once for case-sensititve match, another time for
case-insenstitive match. The overhead isn't that high, but it's
definitely slower than a literal string.

The bigger problem is the chance of a constant being defined under that
name. Not a recommended practice at all.

Sep 13 '06 #3
Jerry Stuckle wrote:

<snip>
>
Put them back in. Not having them is just sloppy programming. And a
few hundred bytes are not going to make much difference.
Dito.
That is good advise.

And even is this 'remove quotes' trick would give you a speedadvantage, it
is not a good move.
Never compromise the readability of your code for a small gain in speed or
size, unless you have a very compelling reason.

If your script is slow find out WHY it is slow first so you know what to
fix. This can be done easily by using microtime or more elegantly by using
a profiler. (I never needed one with PHP. Simple benchmarking with rude
timerfunctions works just fine to spot the CPU-hungy routines/structures.)

If your script is not slow, don't fix it.

A general word of advise: Never try to outsmart a serious
programminglanguage. You can bet on it the makers of the language did that
for you already in ways you cannot think up yourself.
Do yourself a favor and put clearity of your code in the first place.

Regards,
Erwin Moller
Sep 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sandy | last post by:
Hi All, I am a newbie to MySQL and Python. At the first place, I would like to know what are the general performance issues (if any) of using MySQL with Python. By performance, I wanted to...
1
by: DrewM | last post by:
I'm attempting to clean up HTML in a database by quoting all unquoted attributes. So far, I have this: oRegExp.Pattern = "<(+)=(+)>" sHtml = oRegExp.Replace(sHtml, "<$1=""$2"">") which I...
9
by: bluedolphin | last post by:
Hello All: I have been brought onboard to help on a project that had some performance problems last year. I have taken some steps to address the issues in question, but a huge question mark...
1
by: Gerard Marshall Vignes | last post by:
I was recently cautioned against storing an ADO.NET Connection String in the Windows Registry because access to the Windows Registry would be serialized and therefore impact scalability. I have...
2
by: 1944USA | last post by:
I am re-architecting a C# application written as a multithreaded Windows Service and trying to squeeze every bit of performance out of it. 1) Does the thread that an object is instantiated on...
15
by: Sion Arrowsmith | last post by:
I've got an established client-server application here where there is now a need to shovel huge amounts of data (structured as lists of lists) between the two, and the performance bottleneck has...
1
by: dandorey1 | last post by:
I'm currently in the process of writing a realtime telephony application. I've designed it with a fairly simply plugin architecture. When I first started reading about this the general suggestion...
11
by: Paul H | last post by:
Suppose I have a table called tblPeople and I want a field to illustrate whether each person prefers cats or dogs. I could do it one of three ways. 1. A plain text field Create a text field in...
14
by: Sugandh Jain | last post by:
Hi, The warning from Microsoft.Performance Code Analysis check that, its not required to initialize numeric variables to zero, boolean to false and object to null is a good one because CLR does...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.