Java Code Examples for org.apache.commons.lang3.time.StopWatch#getNanoTime()

The following examples show how to use org.apache.commons.lang3.time.StopWatch#getNanoTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoadWrapper.java    From casquatch with Apache License 2.0 6 votes vote down vote up
/**
 * Read the provided object by keys
 * @param obj object to query with
 * @return result of query
 */
private E read(E obj) {
    StopWatch sw = new StopWatch();
    StopWatch dbsw = new StopWatch();
    sw.start();
    log.trace("Reading object with id: "+obj.keys().toString());
    E readObj = null;
    try {
        dbsw.start();
        readObj = db.getById(this.clazz, obj);
        dbsw.stop();
        log.trace("DB Write performed in "+timeFormat(dbsw.getNanoTime())+".");
        log.trace("Read object: "+readObj.toString());
    }
    catch (Exception e) {
        log.error("Failed to read object",e);
        errorCount++;
    }
    sw.stop();
    totalReads++;
    totalDBReadTime=totalDBReadTime+dbsw.getNanoTime();
    totalReadTime=totalReadTime+sw.getNanoTime();
    log.trace("Read performed in "+timeFormat(sw.getNanoTime())+".");
    log.debug("Read Complete. ID: "+obj.keys().toString()+". DB Time: "+timeFormat(dbsw.getNanoTime())+". Total Time:"+timeFormat(sw.getNanoTime())+".");
    return readObj;
}
 
Example 2
Source File: TestTensorAlongDimension.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaVsNative() {
    long totalJavaTime = 0;
    long totalCTime = 0;
    long n = 10;
    INDArray row = Nd4j.create(1, 100);

    for (int i = 0; i < n; i++) {
        StopWatch javaTiming = new StopWatch();
        javaTiming.start();
        row.javaTensorAlongDimension(0, 0);
        javaTiming.stop();
        StopWatch cTiming = new StopWatch();
        cTiming.start();
        row.tensorAlongDimension(0, 0);
        cTiming.stop();
        totalJavaTime += javaTiming.getNanoTime();
        totalCTime += cTiming.getNanoTime();
    }

    System.out.println("Java timing " + (totalJavaTime / n) + " C time " + (totalCTime / n));

}
 
Example 3
Source File: TestTensorAlongDimension.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaVsNative() {
    long totalJavaTime = 0;
    long totalCTime = 0;
    long n = 10;
    INDArray row = Nd4j.create(1, 100);

    for (int i = 0; i < n; i++) {
        StopWatch javaTiming = new StopWatch();
        javaTiming.start();
        row.tensorAlongDimension(0, 0);
        javaTiming.stop();
        StopWatch cTiming = new StopWatch();
        cTiming.start();
        row.tensorAlongDimension(0, 0);
        cTiming.stop();
        totalJavaTime += javaTiming.getNanoTime();
        totalCTime += cTiming.getNanoTime();
    }

    System.out.println("Java timing " + (totalJavaTime / n) + " C time " + (totalCTime / n));

}
 
Example 4
Source File: LoadWrapper.java    From casquatch with Apache License 2.0 5 votes vote down vote up
/**
 * Write the object to the db
 * @param obj object to write
 * @return written object;
 */
private E write(E obj) {

    StopWatch sw = new StopWatch();
    StopWatch dbsw = new StopWatch();
    sw.start();

    try {
        log.trace("Writing object with id "+obj.keys().toString()+" : "+obj.toString());
        dbsw.start();
        db.save(this.clazz, obj);
        dbsw.stop();
        log.trace("DB Write performed in "+timeFormat(dbsw.getNanoTime())+".");
        log.trace("Successfully wrote object: "+obj.toString());
    }
    catch (Exception e) {
        log.error("Failed to write object",e);
        errorCount++;
    }
    sw.stop();
    totalWrites++;
    totalDBWriteTime=totalDBWriteTime+dbsw.getNanoTime();
    totalWriteTime=totalWriteTime+sw.getNanoTime();
    log.trace("Write performed in "+sw.getNanoTime()+"ms");
    log.debug("Write Complete. ID: "+obj.keys().toString()+". DB Time: "+timeFormat(dbsw.getNanoTime())+". Total Time:"+timeFormat(sw.getNanoTime())+".");
    return obj;
}
 
Example 5
Source File: BinarySerdeTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void timeOldVsNew() throws Exception {
    int numTrials = 1000;
    long oldTotal = 0;
    long newTotal = 0;
    INDArray arr = Nd4j.create(100000);
    Nd4j.getCompressor().compressi(arr, "GZIP");
    for (int i = 0; i < numTrials; i++) {
        StopWatch oldStopWatch = new StopWatch();
        // FIXME: int cast
        BufferedOutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream((int) arr.length()));
        DataOutputStream dos = new DataOutputStream(bos);
        oldStopWatch.start();
        Nd4j.write(arr, dos);
        oldStopWatch.stop();
        // System.out.println("Old " + oldStopWatch.getNanoTime());
        oldTotal += oldStopWatch.getNanoTime();
        StopWatch newStopWatch = new StopWatch();
        newStopWatch.start();
        BinarySerde.toByteBuffer(arr);
        newStopWatch.stop();
        //  System.out.println("New " + newStopWatch.getNanoTime());
        newTotal += newStopWatch.getNanoTime();

    }

    oldTotal /= numTrials;
    newTotal /= numTrials;
    System.out.println("Old avg " + oldTotal + " New avg " + newTotal);

}
 
Example 6
Source File: AeronNDArraySerdeTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void timeOldVsNew() throws Exception {
    int numTrials = 1000;
    long oldTotal = 0;
    long newTotal = 0;
    INDArray arr = Nd4j.create(100000);
    Nd4j.getCompressor().compressi(arr, "GZIP");
    for (int i = 0; i < numTrials; i++) {
        StopWatch oldStopWatch = new StopWatch();
        // FIXME: int cast
        BufferedOutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream((int) arr.length()));
        DataOutputStream dos = new DataOutputStream(bos);
        oldStopWatch.start();
        Nd4j.write(arr, dos);
        oldStopWatch.stop();
        // System.out.println("Old " + oldStopWatch.getNanoTime());
        oldTotal += oldStopWatch.getNanoTime();
        StopWatch newStopWatch = new StopWatch();
        newStopWatch.start();
        AeronNDArraySerde.toBuffer(arr);
        newStopWatch.stop();
        //  System.out.println("New " + newStopWatch.getNanoTime());
        newTotal += newStopWatch.getNanoTime();

    }

    oldTotal /= numTrials;
    newTotal /= numTrials;
    System.out.println("Old avg " + oldTotal + " New avg " + newTotal);

}
 
Example 7
Source File: BinarySerdeTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void timeOldVsNew() throws Exception {
    int numTrials = 1000;
    long oldTotal = 0;
    long newTotal = 0;
    INDArray arr = Nd4j.create(100000);
    Nd4j.getCompressor().compressi(arr, "GZIP");
    for (int i = 0; i < numTrials; i++) {
        StopWatch oldStopWatch = new StopWatch();
        BufferedOutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream((int) arr.length()));
        DataOutputStream dos = new DataOutputStream(bos);
        oldStopWatch.start();
        Nd4j.write(arr, dos);
        oldStopWatch.stop();
        // System.out.println("Old " + oldStopWatch.getNanoTime());
        oldTotal += oldStopWatch.getNanoTime();
        StopWatch newStopWatch = new StopWatch();
        newStopWatch.start();
        BinarySerde.toByteBuffer(arr);
        newStopWatch.stop();
        //  System.out.println("New " + newStopWatch.getNanoTime());
        newTotal += newStopWatch.getNanoTime();

    }

    oldTotal /= numTrials;
    newTotal /= numTrials;
    System.out.println("Old avg " + oldTotal + " New avg " + newTotal);

}
 
Example 8
Source File: AeronNDArraySerdeTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void timeOldVsNew() throws Exception {
    int numTrials = 1000;
    long oldTotal = 0;
    long newTotal = 0;
    INDArray arr = Nd4j.create(100000);
    Nd4j.getCompressor().compressi(arr, "GZIP");
    for (int i = 0; i < numTrials; i++) {
        StopWatch oldStopWatch = new StopWatch();
        BufferedOutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream((int) arr.length()));
        DataOutputStream dos = new DataOutputStream(bos);
        oldStopWatch.start();
        Nd4j.write(arr, dos);
        oldStopWatch.stop();
        // System.out.println("Old " + oldStopWatch.getNanoTime());
        oldTotal += oldStopWatch.getNanoTime();
        StopWatch newStopWatch = new StopWatch();
        newStopWatch.start();
        AeronNDArraySerde.toBuffer(arr);
        newStopWatch.stop();
        //  System.out.println("New " + newStopWatch.getNanoTime());
        newTotal += newStopWatch.getNanoTime();

    }

    oldTotal /= numTrials;
    newTotal /= numTrials;
    System.out.println("Old avg " + oldTotal + " New avg " + newTotal);

}
 
Example 9
Source File: MeasureElapsedTime.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void calculate_elapsed_time_in_apache_commons () throws InterruptedException {
	StopWatch stopWatch = new StopWatch();
	stopWatch.start();
	
	Thread.sleep(2); // simulate work
	
	stopWatch.stop();
	long millis = stopWatch.getNanoTime();

	logger.info("time: " + millis); 
	
	assertTrue(millis >= 0);
}