This little tester seems to tell me there's very little value in specifying the size on the constructor of the classes under test. The output has tabs making it suitable for copy-paste into Excel for graphing nearly flat lines.
Tested on Java 1.4 within WSAD 5.1.2 on laptop with 1.6 ghz, 1 gig of 797mhz memory.
Does this seem like a valid test? I thought about baking up the "entryn" strings in an array before running any tests.
Does it suggest the same thing to you?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I think the value in allocating collections at the size you expect them to reach instead of letting them expand "automatically" shows up only with really large collections that strain memory management. The new array creation and copying that occurs with automatic expansion is really quite fast.
I bet that's right. I ran this up to 100,000 entries to get it to run long enough to measure at all. It would be more interesting on a system that's already running into memory issues. I think I'm not going to bother to pre-allocate until I've seen something cause a problem.
Joined: Jan 29, 2003
I tried adding String concatenation to this to compare it to StringBuffer. The warmup() call never returned. I got bored after a few minutes and killed it. I ran it without the warmup and the elapsed time went up on a curve that was getting pretty steep early in the test. Killed again.