After doing a bit of reading, I discovered that there are some differences in the ways you can copy arrays in java. For my application I have a recursive tree of nodes, each containing a 2d board array (8x8).
Through profiler testing, the best thing I could come up with is the java.util.Arrays.copyOf(array) method, which uses the native System.arraycopy.
Even with this, I am spending 80% of my time creating new arrays. If anyone has any ideas on how to speed this up I'd appreciate it. Perhaps going to a 64 item array rather than an 8x8 would be faster. I'll test this shortly.
Copy(Array, Array, Int32) Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 32-bit integer.
Using clone() method. Using arraycopy() method. Using copyOf() method of Arrays class.
arraycopy. Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dest .
arraycopy is a native call (that apparently uses memcpy). Even with the JNI overhead, System. arraycopy runs faster than Arrays. fill().
The fact that you are spending 80% time copying arrays means one of two things:
Your copying performance may already be cutting-edge; consider the architecture of your application instead, try reducing the amount of copied data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With