On Tue, 2002-11-12 at 22:24, Henrik Olsson wrote: > >On Tue, 2002-11-12 at 20:22, Laszlo Hornyak wrote: > >> ok, sorry for the disturbance. > >> > >> Laszlo Hornyak > >> > >> ps: > >> StringBuffering code: > >> time for test: 45479 > >> > >> String += code: > >> time for test: 52011 > > > >+= is slow > > > >+ is faster. > > > The important thing here are not realy the time it takes to do += or + to > strings, the biggest cost in handling strings is the creation and gc > > Creation and destruction of string objects costs alot in the FOP since > there are huge misuse of them. > > se patch 14013 that runs 20-30% faster and the biggest things are > optimization of string handling. > > So I think StringBuffers shall be used instead of adding strings together.
The add and store operation is slow. eg String a = "foo"; a += "bar"; String a = "foo" + "bar"; compiles to approximatly StringBuffer xxx.append("foo").append("bar"); Which is faster than StringBuffer xxx.append("foo"); xxx.append("bar"); It's even slightly faster than StringBuffer xxx.append("foo").append("bar"); understanding what the compiler does is the secret to optimizing Strings. For details of why see my earlier post. > /Henrik -k. -- If you don't test then your code is only a collection of bugs which apparently behave like a working program. Website: http://www.rocketred.com.au/blogs/kevin/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]