0

I used for loop to initialise an array with default value. And I also used Arrays.fill for performance comparison. In every test case for own for loop is faster than Arrays.fill method

If inbuilt method is not giving good performance then why many developer use inbuilt method.

I am not expert in CP so please suggest

Charul
  • 202
  • 2
  • 12
Spsahu
  • 11
  • 1
    How have you measured the performance? Show us the code. – Amongalen May 18 '20 at 11:47
  • 2
    Other than that, readability >> performance most of the time. And micro optimization comes last, usually the problem is with general algorithm. – Amongalen May 18 '20 at 11:48
  • 5
    99.999% chance that they way you measured is wrong. See [How do I write a correct micro-benchmark in Java?](https://stackoverflow.com/q/504103/2711488) – Holger May 18 '20 at 13:07
  • Agree with @Holger. So that linked question may give the best answer to yours. `Arrays.fill()` uses a simple loop, so unless the method call is costly — *very* unlikely — you won’t notice any performance difference in the end. – Ole V.V. May 18 '20 at 16:13

0 Answers0