Please apologize for this lengthy elaboration.

I ran some array copy benchmarks on NT with JDK1.2 and Visual Age
(VAJ2.0).
The results are surprising and indicate major inefficiencies in the
implementation of System.arraycopy(), both in VAJ and the NT JDK.

Other measurements on Solaris seem to tell that the Solaris JDK (1.2?)
uses a better implementation of System.arraycopy().
Has anyone figures from Linux or other environments?

The benchmarks copied all elements from one large array into another
large array (array.length=10^6).
Like this:

byte[] source = new byte[size];
byte[] dest = new byte[size];

//variant A: System.arraycopy()
System.arraycopy(source,0,dest,0,size);

//variant B: dest[i]=source[i]
for (int j=size; --j >= 0; ) dest[j] = source[j];


The measurements show that both VAJ and JDK delegate to pretty much the
same (bad) C implementation of System.arraycopy().
For variant B the JDK1.2 JIT produces code that is *not quicker* than
System.arraycopy()! (Except for byte units).
This is the case even though every single array index access in Java
checks if bounds are legal, while System.arraycopy() needs to perform
bounds checks only once before entering the copy loop. In fast, one
would assume that System.arraycopy() is lightning fast.

Here are the results:

Config: Pentium Pro 200MHz, NT. Compilation without -o flag or any other
optimizer.
All mem is allocated upfront with
java -verbosegc -Xms50m -Xmx50m ch.cern.colt.test.ArrayCopyBenchmark 10
1000000
No gc taking place. No swapping either. Plenty of RAM free. No other
work load biasing results.

Benchmark results given in MB/sec.

VAJ 2.0      | byte int long
----------------------------
arraycopy()  | 44   38  39
a[j]=b[j]    |  3   13  16

JDK 1.2      | byte int long
----------------------------
arraycopy()  | 43   39  38
a[j]=b[j]    | 15   40  40


Enclosed please find the benchmark code.

Mathias Waack wrote:
> I can't reproduce your results. Running the bench on my Solaris Ultra Box
> (333MHz), I've got:
> 
>         byte int long
> array    136 142  136
> =         43  74   78
> 


Does anybody know what is slowing System.arraycopy() on NT so much down?
Has anyone figures from Linux or other environments?

Wolfgang.
-- 
----------------------------------------------------------------------
Wolfgang Hoschek     | e-mail: [EMAIL PROTECTED]
CERN IT Division     | phone:  +41 (22) 767 8089
European Laboratory  | fax:    +41 (22) 767 7155 
for Particle Physics | home:   http://www.cern.ch/CERN/Divisions/EP/HL
----------------------------------------------------------------------

ArrayCopyBenchmark.java

Timer.java

Reply via email to