473,385 Members | 1,343 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,385 software developers and data experts.

Efficiency of str.replace?

For my web-based application, I need to make twelve different calls to
str.replace for the content of /every/ page on /every/ page view (or
find a harder to implement and probably less elegant solution). Would
that be a major performance hit?
Jul 18 '05 #1
2 4890
Leif K-Brooks wrote:
For my web-based application, I need to make twelve different calls to
str.replace for the content of /every/ page on /every/ page view (or
find a harder to implement and probably less elegant solution). Would
that be a major performance hit?


Consider that each call makes a new copy of the whole string. On
the other hand, whether it's a major hit or not depends entirely
on one thing: how many replacements are made. And how big the page
is -- two things. And what you consider "major" to be. There
are three things that this question depends upon, and these are....

Measurement is you only answer. Nobody else can say guess what
you would consider "major". (Not to mention what you'd consider
less elegant. I can think of some elegant, though less simple,
solutions to the potential performance problem, but I wouldn't
think for a moment of implementing them unless some profiling
proved there was a real problem.)

-Peter
Jul 18 '05 #2
On Wed, Jun 23, 2004 at 09:08:43PM -0400, Leif K-Brooks wrote:
For my web-based application, I need to make twelve different calls to
str.replace for the content of /every/ page on /every/ page view (or
find a harder to implement and probably less elegant solution). Would
that be a major performance hit?


$ timeit -s 's = open("/usr/share/dict/words").read()' 's.replace("the", "xyzzy")'
100 loops, best of 3: 8.31e+03 usec per loop

/usr/share/dict/words contains 45k words in 410k bytes, with "the"
appearing on 409 of those lines. When I take the first 50000 bytes of
the file, I get a timing of 360 usec per loop.

Is 100 msec much per page view? Is 4 msec? What's the size of an
average page? I can't answer any of these questions for you.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFA2zosJd01MZaTXX0RAkTQAJwK7cBErVWrJU7zBg1tAW Q6+YDjJgCgqGA6
Ih+9xKTuAUJrFoXHA1hGdes=
=6CMv
-----END PGP SIGNATURE-----

Jul 18 '05 #3

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

Similar topics

2
by: Lee Cullens | last post by:
In my original post I noted my recent exposure to Python and put up a little utility to my iDisk asking for a Pythonese/Efficiency/ Generalese critique. Javier, Kent and Liam were gracious...
31
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant...
6
by: Chris Dunaway | last post by:
I am using a StringBuilder like this: Dim sb As New StringBuilder sb.Append("Text field 1: {TXT1}" & VbCrLf) sb.Append("Text field 2: {TXT2}" & VbCrLf) sb.Append("Text field 3: {TXT3}" &...
4
by: Mark P | last post by:
Consider the following: // Contrast different ways of inserting into a map #include <map> #include <iostream> using namespace std; struct A
335
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
83
by: Licheng Fang | last post by:
Hi, I'm learning STL and I wrote some simple code to compare the efficiency of python and STL. //C++ #include <iostream> #include <string> #include <vector> #include <set> #include...
19
by: vamshi | last post by:
Hi all, This is a question about the efficiency of the code. a :- int i; for( i = 0; i < 20; i++ ) printf("%d",i); b:- int i = 10;
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
2
by: pedalpete | last post by:
Hey mysql gurus, I've got a bit of an efficiency question, and just trying to figure out how best to manage this. For my site HearWhere.com, I have a table which holds artists shows. When i...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?

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.