Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Lesson learned  (Read 2175 times)
0 Members and 1 Guest are viewing this topic.
Offline 20thCenturyBoy

Senior Member


Medals: 3


So much to learn, so little time.


« Posted 2004-08-05 07:59:53 »


String message, line;

for (;;) {
   line = in.readLine();
   message += line;
}


Time taken to download a 1500 line email: 13 secs
Oh dear. Java is so slow! (Reads API...) What's this StringBuffer all about then?


StringBuffer message;
String line;

for (;;) {
   line = in.readLine();
   message.append(line);
}


Time taken to download a 1500 line email: 50ms

Hurrah! Java is fast!

I wish all optimisations were as easy as this!


"I have never done unit testing and I don’t find it a very useful concept" - Jonathan Blow
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2004-08-05 08:51:34 »

I thought the compiler now handled all string concatenation with SB's anyway? And in the trivial analysis of that code there would be no obvious need to through away the intermediate SB between calls. Do you get different behaviour with server compared to client?

malloc will be first against the wall when the revolution comes...
Offline pepe

Junior Member




Nothing unreal exists


« Reply #2 - Posted 2004-08-05 10:28:55 »

i'll bet that if you decompile
1  
2  
3  
4  
 for (;;) {
    line = in.readLine();
    message += line;
}

you'll see something like that:
1  
2  
3  
4  
5  
6  
7  
String message;
 for (;;) {
    line = in.readLine();
    StringBuffer sb = new StringBuffer( message );
    sb.append( line );
    message = sb.toSTring();
}

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #3 - Posted 2004-08-05 14:54:27 »

I think Pepe is correct... all string concatenation is done with SBs, but there is no optimization to keep the same SB across multiple statements, which is essentially what the loop above is all about.

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #4 - Posted 2004-08-05 15:30:17 »

Indeed. For that reason findbugs has a pattern for detecting that kind of stuff.

弾幕 ☆ @mahonnaiseblog
Offline 20thCenturyBoy

Senior Member


Medals: 3


So much to learn, so little time.


« Reply #5 - Posted 2004-08-05 16:07:50 »

Findbugs?  <does Google....>
Ok, that'll be useful then  Grin

"I have never done unit testing and I don’t find it a very useful concept" - Jonathan Blow
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #6 - Posted 2004-08-05 16:58:58 »

Quote
Findbugs?  <does Google....>
Ok, that'll be useful then  Grin


If you were going to post that you googled you might as well have posted the link so I didn't have to take my hand off the mouse Smiley

http://findbugs.sourceforge.net/

Offline 20thCenturyBoy

Senior Member


Medals: 3


So much to learn, so little time.


« Reply #7 - Posted 2004-08-06 03:04:54 »

Quote
If you were going to post that you googled you might as well have posted the link so I didn't have to take my hand off the mouse

Sorry!

I really must check out some more Java stuff on Sourceforge, I'll bet there is a ton of stuff that I'm missing out on.

"I have never done unit testing and I don’t find it a very useful concept" - Jonathan Blow
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #8 - Posted 2004-08-06 04:24:30 »

Yeah.. I just installed the FindBugs plugin for Eclipse.  It found a few things in my project that needed fixing.

Offline aldacron

Senior Member


Medals: 9
Exp: 16 years


Java games rock!


« Reply #9 - Posted 2004-08-06 05:00:10 »

Quote

Time taken to download a 1500 line email: 13 secs
Oh dear. Java is so slow! (Reads API...) What's this StringBuffer all about then?


Java 5.0 has a StringBuilder class which is the same as StringBuffer, but isn't synchronized.  So when you start using 5.0 perhaps you'll want to swtich to the new class.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline abies

Senior Member





« Reply #10 - Posted 2004-08-06 08:27:45 »

I have done some experiments with StringBuilder under server hotspot and I was not able to create any microbenchmark where it was noticeably faster. For me, it looks like hotspot is able to determine that this object is local and does not need synchronization ?? Situation will probably look different if you will pass StringBuffer/StringBuilder between methods.

Artur Biesiadowski
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 22:08:39

Riven (25 views)
2014-07-29 19:09:19

Riven (15 views)
2014-07-29 19:08:52

Dwinin (12 views)
2014-07-29 11:59:34

E.R. Fleming (33 views)
2014-07-29 04:07:13

E.R. Fleming (12 views)
2014-07-29 04:06:25

pw (43 views)
2014-07-24 02:59:36

Riven (43 views)
2014-07-23 22:16:32

Riven (30 views)
2014-07-23 22:07:15

Riven (31 views)
2014-07-23 21:56:16
List of Learning Resources
by SilverTiger
2014-07-31 19:29:50

List of Learning Resources
by SilverTiger
2014-07-31 19:26:06

List of Learning Resources
by SilverTiger
2014-07-31 14:54:12

HotSpot Options
by dleskov
2014-07-08 04:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 01:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 01:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 12:13:37

HotSpot Options
by Roquen
2014-05-15 10:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!