Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.imglib2.img.basictypeaccess.ByteAccess;
- import net.imglib2.img.basictypeaccess.array.ByteArray;
- public class ByteAccessCopyTest
- {
- public static void main( final String args[] )
- {
- final int iterations = 100000;
- final int size = 1000000;
- final ByteArray source = new ByteArray( size );
- final ByteArray target = new ByteArray( size );
- for ( int i = 0; i < iterations; ++i )
- {
- copy( source, target, size );
- }
- final long tStartAccessCopy = System.nanoTime();
- for ( int i = 0; i < iterations; ++i )
- {
- copy( source, target, size );
- }
- final long tStopAccessCopy = System.nanoTime();
- final long tAccessCopy = tStopAccessCopy - tStartAccessCopy;
- for ( int i = 0; i < iterations; ++i )
- {
- System.arraycopy( source.getCurrentStorageArray(), 0, target.getCurrentStorageArray(), 0, size );
- }
- final long tStartArraycopy = System.nanoTime();
- final byte[] sourceArr = source.getCurrentStorageArray();
- final byte[] targetArr = target.getCurrentStorageArray();
- for ( int i = 0; i < iterations; ++i )
- {
- System.arraycopy( sourceArr, 0, targetArr, 0, size );
- }
- final long tStopArraycopy = System.nanoTime();
- final long tArraycopy = tStopArraycopy - tStartArraycopy;
- System.out.println( "access copy: " + tAccessCopy * 1.0 / iterations );
- System.out.println( "array copy: " + tArraycopy * 1.0 / iterations );
- }
- private static final void copy( final ByteAccess source, final ByteAccess target, final int size )
- {
- for ( int i = 0; i < size; ++i )
- {
- target.setValue( i, source.getValue( i ) );
- }
- }
- }
Add Comment
Please, Sign In to add comment