Package org.apache.niolex.commons.test.StopWatch

Examples of org.apache.niolex.commons.test.StopWatch.Stop


    public static void main(String[] args) {
        StopWatch w = new StopWatch(1);
        w.begin(true);
        for (int i = 0; i < 1000; ++i) {
            Map<Integer, Boolean> map = Maps.newHashMap();
            Stop s = w.start();
            for (int j = 0; j < 10000; ++j) {
                map.put(j, j % 2 == 0);
            }
            for (int j = 0; j < 10000; ++j) {
                Check.isTrue(map.get(j).booleanValue() == (j % 2 == 0));
            }
            s.stop();
        }
        w.done();
        w.print();
        // --
        w.begin(true);
        for (int i = 0; i < 1000; ++i) {
            TIntCharMap primary = new TIntCharHashMap();
            Stop s = w.start();
            for (int j = 0; j < 10000; ++j) {
                primary.put(j, (char)((j % 2) + '0'));
            }
            for (int j = 0; j < 10000; ++j) {
                Check.isTrue(primary.get(j) == (char)((j % 2) + '0'));
            }
            s.stop();
        }
        w.done();
        w.print();
        // --
        w.begin(true);
        for (int i = 0; i < 1000; ++i) {
            Int2CharMap int2c = new Int2CharOpenHashMap();
            Stop s = w.start();
            for (int j = 0; j < 10000; ++j) {
                int2c.put(j, (char)((j % 2) + '0'));
            }
            for (int j = 0; j < 10000; ++j) {
                Check.isTrue(int2c.get(j) == (char)((j % 2) + '0'));
            }
            s.stop();
        }
        w.done();
        w.print();
    }
View Full Code Here


    StopWatch w = new StopWatch(1);
    w.begin(true);
    // This is slower!
    for (int i = 0; i < 1000; ++i) {
        IntList inList = new ArrayIntList(10000);
      Stop s = w.start();
      for (int j = 0; j < 10000; ++j) {
        inList.add(j);
      }
      s.stop();
    }
    w.done();
    w.print();
    // ------------
    w = new StopWatch(1);
    w.begin(true);
    for (int i = 0; i < 1000; ++i) {
        ArrayList<Integer> oList = new ArrayList<Integer>(10000);
      Stop s = w.start();
      for (int j = 0; j < 10000; ++j) {
        oList.add(j);
      }
      s.stop();
    }
    w.done();
    w.print();
  }
View Full Code Here

  public static void main(String[] argv) throws IOException {
    StopWatch sw = new StopWatch(10);

    sw.begin(true);
    for (int i = 0; i < 500; ++i) {
      Stop s = sw.start();
      int k = directRead();
      if (k != 9910842) {
        System.out.println("ERR " + k);
        break;
      }
      s.stop();
    }
    sw.done();
    sw.print();

    sw.begin(true);
    for (int i = 0; i < 500; ++i) {
      Stop s = sw.start();
      int k = bufferRead();
      if (k != 9910842) {
        System.out.println("ERR " + k);
        break;
      }
      s.stop();
    }
    sw.done();
    sw.print();

    RandomAccessFile file = new RandomAccessFile("D:\\data\\miui\\MiFlash20120723.zip", "r");
        FileChannel channel = file.getChannel();
        long tt = file.length();
        MappedByteBuffer map = channel.map(MapMode.READ_ONLY, 0, tt);
    sw.begin(true);
    for (int i = 0; i < 500; ++i) {
      Stop s = sw.start();
      int k = mmapRead(map, tt);
      if (k != 9910842) {
        System.out.println("ERR " + k);
        break;
      }
      s.stop();
    }
    sw.done();
    sw.print();
    map.clear();
        channel.close();
View Full Code Here

  public static void main(String[] argv) throws IOException {
    StopWatch sw = new StopWatch(10);

    sw.begin(true);
    for (int i = 0; i < 500; ++i) {
      Stop s = sw.start();
      int k = directRead();
      if (k != 9910842) {
        System.out.println("ERR " + k);
        break;
      }
      s.stop();
    }
    sw.done();
    sw.print();

    sw.begin(true);
    for (int i = 0; i < 500; ++i) {
      Stop s = sw.start();
      int k = bufferRead();
      if (k != 9910842) {
        System.out.println("ERR " + k);
        break;
      }
      s.stop();
    }
    sw.done();
    sw.print();

    sw.begin(true);
    for (int i = 0; i < 500; ++i) {
      Stop s = sw.start();
      int k = mmapRead();
      if (k != 9910842) {
        System.out.println("ERR " + k);
        break;
      }
      s.stop();
    }
    sw.done();
    sw.print();
  }
View Full Code Here

    wr.clean();

    sw.begin(true);
    System.out.println("bufferWrite");
    for (int i = 0; i < RUN_ITER; ++i) {
      Stop s = sw.start();
      wr.bufferWrite();
      s.stop();
    }
    sw.done();
    sw.print();
    wr.clean();

    sw.begin(true);
    System.out.println("directWrite");
    for (int i = 0; i < RUN_ITER; ++i) {
      Stop s = sw.start();
      wr.directWrite();
      s.stop();
    }
    sw.done();
    sw.print();
    wr.clean();

    sw.begin(true);
    System.out.println("randomWrite");
    for (int i = 0; i < RUN_ITER; ++i) {
      Stop s = sw.start();
      wr.randomWrite();
      s.stop();
    }
    sw.done();
    sw.print();
    wr.clean();

    sw.begin(true);
    System.out.println("channelWrite");
    for (int i = 0; i < RUN_ITER; ++i) {
      Stop s = sw.start();
      wr.channelWrite();
      s.stop();
    }
    sw.done();
    sw.print();
    wr.clean();
View Full Code Here

   * Test method for {@link org.apache.niolex.commons.test.StopWatch#start()}.
   * @throws InterruptedException
   */
  @Test
  public void testCStart() throws Exception {
    Stop s = sw.start();
    Stop s1 = sw.start();
    Field f = FieldUtil.getField(Stop.class, "startTime");
        long value = System.currentTimeMillis() - 10;
        FieldUtil.setFieldValue(s, f, value);
        FieldUtil.setFieldValue(s1, f, value);
    s.stop();
    s1.stop();
    s = sw.start();
    FieldUtil.setFieldValue(s, f, value - 10);
    s.stop();
    s = sw.start();
    FieldUtil.setFieldValue(s, f, value - 1490);
View Full Code Here

   * @throws IllegalAccessException
   * @throws IllegalArgumentException
   */
  @Test
  public void testFCStart() throws InterruptedException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    Stop s = sw.start();
    Stop s1 = sw.start();
    Field f = FieldUtil.getField(Stop.class, "startTime");
    long value = System.currentTimeMillis() - 10;
    FieldUtil.setFieldValue(s, f, value);
    FieldUtil.setFieldValue(s1, f, --value);
    s.stop();
    s1.stop();
    s = sw.start();
    FieldUtil.setFieldValue(s, f, value - 10);
    s.stop();
    s = sw.start();
    FieldUtil.setFieldValue(s, f, value - 1490);
View Full Code Here

        sw.begin(false);
        MultiPerformance perf = new MultiPerformance(20, 1, 200) {

            @Override
            protected void run() {
                Stop start = sw.start();
                ThreadUtil.sleep(MathUtil.randInt(10));
                start.stop();
            }};
        perf.start();
        sw.done();
        sw.print();
    }
View Full Code Here

TOP

Related Classes of org.apache.niolex.commons.test.StopWatch.Stop

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.