Is Java’s System.arraycopy() efficient for small arrays, or does the fact that it’s a native method make it likely to be substantially less efficient than a simple loop and a function call?
Do native methods incur additional performance overhead for crossing some kind of Java-system bridge?
Expanding a little on what Sid has written, it’s very likely that
System.arraycopyis just a JIT intrinsic; meaning that when code callsSystem.arraycopy, it will most probably be calling a JIT-specific implementation (once the JIT tagsSystem.arraycopyas being “hot”) that is not executed through the JNI interface, so it doesn’t incur the normal overhead of native methods.In general, executing native methods does have some overhead (going through the JNI interface, also some internal JVM operations cannot happen when native methods are being executed). But it’s not because a method is marked as “native” that you’re actually executing it using JNI. The JIT can do some crazy things.
Easiest way to check is, as has been suggested, writing a small benchmark, being careful with the normal caveats of Java microbenchmarks (warm up the code first, avoid code with no side-effects since the JIT just optimizes it as a no-op, etc).