Say I want to compare the performance of Java's StringBuilder.toString() with new String(char[]) for strings from one to 3000 characters in length. I do know beforehand how long the resulting string will be. How many times should I try each length, and how can I collect the results into usable information? I'm mostly interested execution time, but if there are any memory usage quirks I'd like to know about them also.
Tell me more
×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for
software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.
|
You didn't say how much precision you need -- do you just want to know which is faster, or do you want to know how much faster? Here are some factors that interfere with benchmarks like that:
In any case, I suggest figuring it out empirically. Write the benchmark with a sample size of N and write down the results. Repeat with larger multiples of N, e.g. 1000, 10000, 1000000, etc., until the results converge to as much precision as you need. |
||||
|
|
char[].toString()does what you think it does. Here's my example: i.stack.imgur.com/8i2Dd.png - That's entirely tangential to how you would test something like it, of course, to which I can't add much to u246's answer! – corsiKa♦ Mar 15 at 15:52