20 July 2009
06 July 2009
Putting it together
We've been code-reviewing some of the Java code on the project, and the question of optimal string concatenation came up. While others on the team were loyal to
I scratched a little deeper, and found that a more complete answer to "which is better?" depends in part on what compiler optimizations you're using, as Apurba and Pavitar point out. Schneide Blog also notes that it's hard to measure string concatenation performance in isolation from the real-world context where you're performing the operation.
Another point to keep in mind: what are we trying to optimize? Run-time speed, memory usage, or something else? Nicholas Hagen, in his benchmarking tests, helpfully provides both execution times and object creation counts. Hagen gives some rules of thumb. I have added emphasis to the most important one for us, and fortunately it matches our informal shop standards.
Fortunately for this project, all the Java string manipulation is done in backend systems on an moderate-volume intranet, so these general guidelines are sufficient; we haven't needed to do extensive profiling to find hot spots. The public-facing web site uses different technology altogether.
StringBuilder.append(), I had relied on the + operator, following the advice of Ian Darwin in his Java Cookbook 2/e:
3.4.1. Problem
You need to put someStringpieces (back) together.
3.4.2. Solution
Use string concatenation: the + operator. The compiler implicitly constructs aStringBuilderfor you and uses itsappend( )methods. Better yet, construct and use it yourself.
I scratched a little deeper, and found that a more complete answer to "which is better?" depends in part on what compiler optimizations you're using, as Apurba and Pavitar point out. Schneide Blog also notes that it's hard to measure string concatenation performance in isolation from the real-world context where you're performing the operation.
Another point to keep in mind: what are we trying to optimize? Run-time speed, memory usage, or something else? Nicholas Hagen, in his benchmarking tests, helpfully provides both execution times and object creation counts. Hagen gives some rules of thumb. I have added emphasis to the most important one for us, and fortunately it matches our informal shop standards.
- DO use the plus operator if all operands are constants
- DO use
String.concatif only concatenating 2 strings- DO use
StringBuilderwithin a for loop when updating values- DO use
StringBuilderif concatenating more than 2 strings- DO use
StringBuilderrather than re-assigning variables multiple times- DO ensure
StringBuilderhas proper sizing
Fortunately for this project, all the Java string manipulation is done in backend systems on an moderate-volume intranet, so these general guidelines are sufficient; we haven't needed to do extensive profiling to find hot spots. The public-facing web site uses different technology altogether.
01 July 2009
Everything's better on a stick
Ryan Paul reports on the first official release of the Sugar educational software platform for removable media. Sugar was the Linux-derived OS distributed with the first generation of XO computers. With the release of Sugar on a Stick (SoaS), now it is the case that
When Sugar runs from a memory stick, the user's files can be stored directly on the device. This completely portable and self-contained approach makes it possible for students to use at school and at home. It also makes it easy for schools to repurpose existing computers and get them up and running with the Sugar learning environment with minimal difficulty and investment.
30 May 2009
D.I.Y.
Steve Chamberlin has hand-built a computer using logic chips, a wire-wrapping tool, and a lot of patience. Meet BMOW (Big Mess o' Wires).
07 May 2009
Ce n'est rien
I love my user representatives on this project. They were so pleased by a feature that I've just finished—something simple that took me less than a week to write, but will make the editors' and producers' job so much easier, eliminating repetitive clicking and typing steps—that they asked me to add "Hooray!" to the text of the confirmation dialog box. Who am I to refuse?
Subscribe to:
Posts (Atom)