News for hackers. Stuff that matters.
Re:A Million Lines of Bad Code by Tossrock on Friday April 17, 2015 @04:44PM (#9397105)
Factually incorrect. Creating new strings by concatenation requires reallocation because Strings are immutable in java. Using a Builder is over 700x faster:

Concat code: http://pastebin.com/CcezmJbf

Builder code: http://pastebin.com/Dd6kzcKa

Results, using JRE 7:

> time java concat data.blk Finished. java foo data.blk 170.08s user 1.52s system 102% cpu 2:48.12 total

> time java builder data.blk Finished. java builder data.blk 0.30s user 0.05s system 151% cpu 0.230 total

Re:A Million Lines of Bad Code by jmgao on Friday April 17, 2015 @05:02PM (#9397184)
This is true, javac only replaces individual concatentations with use of a StringBuilder, so foo + bar + baz + "!" is fast, but performing a concatenation in a loop does multiple copies for each iteration. It (or the JIT) could conceivably do escape analysis to optimize simple cases like this, but it doesn't.

builder: http://hastebin.com/qadusoriqa.cs

concat: http://hastebin.com/nasukuxemi.cs

Re:A Million Lines of Bad Code by Sevzinn on Friday April 17, 2015 @04:50PM (#9397129)
What about the time to write the program?
Re:A Million Lines of Bad Code by Tossrock on Friday April 17, 2015 @05:01PM (#9397182)
About the same.