473,748 Members | 7,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

jython and concatenation of strings

Hello

I found that price of += operator on string is too high in jython. For
example 5000 such operations took 90 seconds (i generated html copy of
table with 1000 rows and 5 columns). Generation of row data into separate
string and joining after lead to time 13 seconds !!!

What's alternative way to do that ? (similiar parts of my code are terribbly
slow and such simple solution as above didn't help).
Thanks,
Jan
Jul 18 '05 #1
5 6906
> I found that price of += operator on string is too high in jython. For
example 5000 such operations took 90 seconds (i generated html copy of
table with 1000 rows and 5 columns). Generation of row data into separate
string and joining after lead to time 13 seconds !!!


Its generally not recommended to use simple string concatenation for
building larger strings - neither in python nor in java/jython.

afaik there are two solutions to this: The java-way and the jython way:

java: Use StringBuffer
python: use a list, and append the strings to that. Then, when you want the
result, do

"".join(stringl ist)

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Jan Gregor wrote:
Hello

I found that price of += operator on string is too high in jython. For
example 5000 such operations took 90 seconds (i generated html copy of
table with 1000 rows and 5 columns). Generation of row data into separate
string and joining after lead to time 13 seconds !!!

What's alternative way to do that ? (similiar parts of my code are terribbly
slow and such simple solution as above didn't help).


I don't use Jython, but are you not able to do something like:

string_list = []
for ... in ...:
...
string_list.app end(...)
...
string = ''.join(string_ list)

This is the usual Python idiom and is usually faster than the += idiom.

Note too that +ing strings in Java also has this problem -- hence
StringBuffer or whatever it's called.

Steve
Jul 18 '05 #3
Ok, thanks. I didn't think that += operator is nondestructive operation
- but strings are immutable so this makes sense.

On 2004-12-13, Diez B. Roggisch <de*********@we b.de> wrote:
I found that price of += operator on string is too high in jython. For
example 5000 such operations took 90 seconds (i generated html copy of
table with 1000 rows and 5 columns). Generation of row data into separate
string and joining after lead to time 13 seconds !!!


Its generally not recommended to use simple string concatenation for
building larger strings - neither in python nor in java/jython.

afaik there are two solutions to this: The java-way and the jython way:

java: Use StringBuffer
python: use a list, and append the strings to that. Then, when you want the
result, do

"".join(stringl ist)

Jul 18 '05 #4
StringBuffer class from java was right solution - yours looses encoding,
and in jython I was unable to get it back - in python it worked fine.

Jan
I don't use Jython, but are you not able to do something like:

string_list = []
for ... in ...:
...
string_list.app end(...)
...
string = ''.join(string_ list)

This is the usual Python idiom and is usually faster than the += idiom.

Note too that +ing strings in Java also has this problem -- hence
StringBuffer or whatever it's called.

Steve

Jul 18 '05 #5
Jan Gregor wrote:
StringBuffer class from java was right solution - yours looses encoding,
and in jython I was unable to get it back - in python it worked fine.


If you mean that Jython returned a string, when the inputs were unicode, then
that can probably be fixed with:

result = u''.join(string _list)

(Python switches to the unicode version automatically if it finds any unicode
strings in the supplied sequence. Jython may not do that - I'm not a Jython user
though, so I'm not sure).

Cheers,
Nick.

--
Nick Coghlan | nc******@email. com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #6

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

Similar topics

6
3676
by: Jonathan | last post by:
Why did the designers of PHP decide to use period (".") as the string concatenation operator rater than the obviously more logical plus ("+")? //JJ
5
3642
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
1
2351
by: Fahd Khan | last post by:
Hi team! While troubleshooting a crash I had while using BitTorrent where the torrent's target file names didn't fall into the ascii range I was playing around in the interpreter and noticed this behaviour: >>> u'\u12345' + 'foo' u'\u12345foo' >>> u'\u12345' u'foo' u'\u12345foo' >>> u'\u12345' + u'foo'.encode('ascii') u'\u12345foo'
37
4719
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie, 20-30k), what are the performance differences (if any with something as trivial as this) between initializing a new instance of StringBuilder with a specified capacity vs. initializing a new instance without... (the final length is not fixed) ie,
23
6253
by: Bonj | last post by:
what is the correct form of string concatenation in VB.NET, + or &? Both seem to work, but which is correct? I know it's + in C# and & in VB6, but which in VB.NET?
3
3083
by: Mythran | last post by:
Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size? Dim a As String = "bah" Dim b As String = "bah2" Dim c As String = a & b Dim d As String = String.Concat(a, b) string a = "bah"; string b = "bah2";
33
4686
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most of articles I read from different experts and programmers tell me that their "gut feelings" for using stringBuilder instead of string concatenation is when the number of string concatunation is more then N ( N varies between 3 to max 15 from...
34
2662
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ____________ THE OVERVIEW I don't remember where I picked it up, but I remember reading years ago that the simple, obvious Python approach for string concatenation: x = "a" + "b"
1
1715
by: Ant | last post by:
Hi All, I'm looking to provide online python documentation for several jython modules: does anyone know if there are tools to create documentation from docstrings that work in Jython? Jython doesn't provide the pydoc module. I've looked into HappyDoc, which is supposed to work on jython as well as python (since it parses the code tree rather than loading the module), but it seems broken at the moment. It seems to recognise
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9372
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 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...
0
8243
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
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...
0
6074
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();...
0
4606
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...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.