Esempio n. 1
0
  private static int runByteBuffer(cl.inria.stiq.utils.ByteBuffer aBuffer, int aCount) {
    int t = 0;
    for (int i = 0; i < aCount; i++) {
      aBuffer.position(0);
      for (int j = 0; j < 1000; j++) t += aBuffer.getInt();
    }

    return t;
  }
Esempio n. 2
0
  public static void main(String[] args) {
    final cl.inria.stiq.utils.ByteBuffer theByteBuffer =
        cl.inria.stiq.utils.ByteBuffer.allocate(4096);
    final java.nio.ByteBuffer theJByteBuffer = java.nio.ByteBuffer.allocate(4096);
    final java.nio.IntBuffer theJByteBufferAsIntBuffer = theJByteBuffer.asIntBuffer();
    final java.nio.IntBuffer theJIntBuffer = java.nio.IntBuffer.allocate(1024);
    theJByteBuffer.order(ByteOrder.nativeOrder());
    final int[] theArray = new int[1024];

    runByteBuffer(theByteBuffer, N);
    BenchResults b =
        BenchBase.benchmark(
            new Runnable() {
              public void run() {
                int t = runByteBuffer(theByteBuffer, N);
                System.out.println(t);
              }
            });
    System.out.println("ByteBuffer: " + b);

    runJByteBuffer(theJByteBuffer, N);
    b =
        BenchBase.benchmark(
            new Runnable() {
              public void run() {
                int t = runJByteBuffer(theJByteBuffer, N);
                System.out.println(t);
              }
            });
    System.out.println("Java ByteBuffer: " + b);

    runJIntBuffer(theJIntBuffer, N);
    b =
        BenchBase.benchmark(
            new Runnable() {
              public void run() {
                int t = runJIntBuffer(theJIntBuffer, N);
                System.out.println(t);
              }
            });
    System.out.println("Java IntBuffer: " + b);

    runJByteBufferAsIntBuffer(theJByteBufferAsIntBuffer, N);
    b =
        BenchBase.benchmark(
            new Runnable() {
              public void run() {
                int t = runJByteBufferAsIntBuffer(theJByteBufferAsIntBuffer, N);
                System.out.println(t);
              }
            });
    System.out.println("Java ByteByffer as IntBuffer: " + b);

    runArray(theArray, N);
    b =
        BenchBase.benchmark(
            new Runnable() {
              public void run() {
                int t = runArray(theArray, N);
                System.out.println(t);
              }
            });
    System.out.println("Array: " + b);
  }