Package com.barchart.udt.util

Examples of com.barchart.udt.util.StopWatch


  }

  static void testJava() throws Exception {

    long nanos;
    StopWatch timer = new StopWatch();

    timer.start();
    for (int k = 0; k < COUNT; k++) {
      // baseline
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("baseline nanos={}", nanos);

    timer.start();
    for (int k = 0; k < COUNT; k++) {
      // small array
      byte[] array = new byte[128];
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("make small array; nanos={}", nanos);

    timer.start();
    for (int k = 0; k < COUNT; k++) {
      // medium array
      byte[] array = new byte[1024];
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("make medium array; nanos={}", nanos);

    int[] arrayInt = new int[SIZE];
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      Arrays.fill(arrayInt, 1235678);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT / SIZE;
    log.info("fill array; nanos={}", nanos);

    //

    Integer[] array = new Integer[1024];
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      for (Integer i : array) {
        // iterate array
        Integer x = i;
      }
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT / 1024;
    log.info("iterate array; nanos={}", nanos);

    // SET
    Set<Integer> set = new HashSet<Integer>();
    for (int k = 0; k < 1024; k++) {
      set.add(k);
    }
    //
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      for (Integer i : set) {
        // iterate set
        Integer x = i;
      }
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT / 1024;
    log.info("iterate set; nanos={}", nanos);
    //
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      Object[] x = set.toArray();
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("set to array; nanos={}", nanos);

  }
View Full Code Here


  static void testJNI() throws Exception {

    SocketUDT socket = new SocketUDT(TypeUDT.DATAGRAM);

    long nanos;
    StopWatch timer = new StopWatch();

    timer.start();
    for (int k = 0; k < COUNT; k++) {
      socket.testEmptyCall0();
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("empty call; nanos={}", nanos);

    timer.start();
    for (int k = 0; k < COUNT * 10; k++) {
      int[] array = socket.testMakeArray0(SIZE);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT / 10;
    log.info("make arrray; nanos={}", nanos);

    int[] arrayInt = new int[SIZE];
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      socket.testGetSetArray0(arrayInt, true);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("get/set/update array; nanos={}", nanos);
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      socket.testGetSetArray0(arrayInt, false);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("get/set/abort array; nanos={}", nanos);

    Object[] array = new Object[SIZE];
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      socket.testIterateArray0(array);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT / SIZE;
    log.info("iterate object array; nanos={}", nanos);

    //
    Set<Object> set = new HashSet<Object>();
    for (int k = 0; k < SIZE; k++) {
      set.add(k);
    }
    timer.start();
    for (int k = 0; k < COUNT / 10; k++) {
      socket.testIterateSet0(set);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT / SIZE * 10;
    log.info("iterate object set; nanos={}", nanos);

    //

    final int FILL_SIZE = 16;

    byte[] fillArray = new byte[FILL_SIZE];
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      socket.testFillArray0(fillArray);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("fillArray; nanos={}", nanos);

    ByteBuffer fillBuffer = ByteBuffer.allocateDirect(FILL_SIZE);
    timer.start();
    for (int k = 0; k < COUNT; k++) {
      socket.testFillBuffer0(fillBuffer);
    }
    timer.stop();
    nanos = timer.nanoTime() / COUNT;
    log.info("fillBuffer; nanos={}", nanos);

  }
View Full Code Here

    StreamClient client = new StreamClient(TypeUDT.DATAGRAM, serverAddress) {
      @Override
      public void run() {
        try {
          final int loop = 100;
          StopWatch timer = new StopWatch();
          timer.start();
          for (int k = 0; k < loop; k++) {
            for (int index = Byte.MIN_VALUE; index <= Byte.MAX_VALUE; index++) {
              streamOut.write(index);
            }
            for (int index = Byte.MIN_VALUE; index <= Byte.MAX_VALUE; index++) {
              int value = streamIn.read();
              assertEquals(value, index);
            }
          }
          timer.stop();
          log.info("timer : {}", timer.nanoString());
          synchronized (this) {
            this.notifyAll();
          }
        } catch (Exception e) {
          log.error("client; {}", e.getMessage());
View Full Code Here

        final int loop = 10000;
        final int size = 1000;
        final byte[] arrayOut = new byte[size];
        final byte[] arrayIn = new byte[size];
        try {
          final StopWatch timer = new StopWatch();
          timer.start();
          for (int k = 0; k < loop; k++) {
            random.nextBytes(arrayOut);
            streamOut.write(arrayOut);
            final int count = streamIn.read(arrayIn);
            assertEquals(count, size);
            assertTrue(Arrays.equals(arrayIn, arrayOut));
          }
          timer.stop();
          log.info("timer : {}", timer.nanoString());
          synchronized (this) {
            this.notifyAll();
          }
        } catch (Exception e) {
          log.error("client; {}", e.getMessage());
View Full Code Here

        final int loop = 3;
        final int size = 100;
        final byte[] arrayOut = new byte[size];
        final byte[] arrayIn = new byte[size];
        try {
          final StopWatch timer = new StopWatch();
          timer.start();
          for (int k = 0; k < loop; k++) {
            random.nextBytes(arrayOut);
            streamOut.write(arrayOut);
            final int count = streamIn.read(arrayIn);
            assertEquals(count, size);
            assertTrue(Arrays.equals(arrayIn, arrayOut));
          }
          timer.stop();
          log.info("timer : {}", timer.nanoString());
          synchronized (this) {
            this.notifyAll();
          }
        } catch (Exception e) {
          log.error("client; {}", e.getMessage());
View Full Code Here

TOP

Related Classes of com.barchart.udt.util.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.