473,396 Members | 2,004 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,396 software developers and data experts.

Trivial question of execution speed

Hi,

I'm trying to write fast code, and I'm wondering which is faster,
generating strings with double quotes or single quotes - aka, $string
= "My name is $name"; or $string = 'My name is '.$name;.

Also, if you have any tips for writing fast code, please share
them :-).

Thanks,

--James.
Feb 15 '08 #1
2 1075
jamesgoode wrote:
I'm trying to write fast code, and I'm wondering which is faster,
generating strings with double quotes or single quotes - aka, $string
= "My name is $name"; or $string = 'My name is '.$name;.
There is no noticeable
Also, if you have any tips for writing fast code, please share
them :-).
Skip premature optimization altogether[1], and concentrate on programming
efficient algorithms[2][3].

[1]http://en.wikipedia.org/wiki/Optimization_(computer_science)#When_to_optimize
[2]http://en.wikipedia.org/wiki/Computational_complexity_theory
[3]http://en.wikipedia.org/wiki/Big_O_notation

In other words, how you concatenate strings won't be a bottleneck in your
application. Unindexed databases or unnefficient ways to
search/update/manipulate data will be.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Con tecnología AMANO(tm).
Feb 15 '08 #2
..oO(jamesgoode)
>I'm trying to write fast code, and I'm wondering which is faster,
generating strings with double quotes or single quotes - aka, $string
= "My name is $name"; or $string = 'My name is '.$name;.
$string = sprintf('My name is %s', $name);

Yes, I've seen cases where this was faster than a sinqle-quoted string
with concatenation.

The point is: You won't notice any difference unless you call this line
a billion times. Google "premature optimization".
>Also, if you have any tips for writing fast code, please share
them :-).
Get a profiler to find the real bottlenecks in your code, _then_ start
thinking about optimization. Usually this means to modify the algorithm,
not the used language constructs. A poorly written QuickSort will still
almost always be faster than a highly optimized BubbleSort.

Micha
Feb 15 '08 #3

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

Similar topics

25
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr...
3
by: linvin333 | last post by:
Hi, Does function overloading affect the speed of execution of the program ? If so what is the reason ? How does it compare with a speed of a program using non-overloded functions ? Linny
6
by: | last post by:
Assume that we have a complex application with many math operations and it is written in an ANSI C++ code and running on a single PC without any problem. Is there an automatic way to execute the...
8
by: djwhisky | last post by:
Hi there - i'm hoping someone can help me! I'm having a problem with a live database that i'm running on MSDE - It seems to have slowed down quite considerably from the test environment (even...
14
by: Michel Esber | last post by:
Linux RH 4.0 running DB2 V8 FP 11. I have a table with ~ 11M rows and running DELETE statements is really slow. Deleting 1k rows takes more than 3 minutes. If I run select statements on the same...
40
by: kavi | last post by:
Hello friends, Could any one tell the way of calculating the speed of c program execution?
1
by: Kelie | last post by:
hello, would there be any speed increase in code execution after python code being compiled into exe file with py2exe? thanks, kelie
25
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
1
by: =?Utf-8?B?TWFyayBT?= | last post by:
I have an application that consists of a managed C++ wrapper around an unmanaged C++ "engine" that performs a very processor intensive task. In the application I create two instances of the...
17
by: Suresh Pillai | last post by:
I am performing simulations on networks (graphs). I have a question on speed of execution (assuming very ample memory for now). I simplify the details of my simulation below, as the question I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.