Java's varargs performance

Static list of arguments is quite different from an array. When you pass them that way, compiler reserves space for the references and populates them when the method is called.

Varargs is an equivalent of array. To call such a method, it's necessary to create and populate array at run time. That's why you observe the difference.

String[] and String... are synonyms. If you compared them, you should see identical performance.


Using both the latest JRE6 and JRE7 I get different results than yours and they indicate that varargs are 5 times faster:

69
69
311

However, I would not jump to conclusions because this benchmark has several flaws: the parameters are not used in the function; the function doesn't do anything; the arguments have the same value. JIT can easily optimize this code and inline function calls. I modified your example to address the aforementioned obvious problems and got the following results:

627
7470
7844

The conclusion is: don't hesitate to use varargs. If your function is trivial then its call be inlined by the JIT, and if it's not then the overhead of varargs will likely be negligible.