Example usage for java.lang System nanoTime

List of usage examples for java.lang System nanoTime

Introduction

In this page you can find the example usage for java.lang System nanoTime.

Prototype

@HotSpotIntrinsicCandidate
public static native long nanoTime();

Source Link

Document

Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.

Usage

From source file:info.novatec.flyway.branching.extension.StandardMigrationIntegrationTest.java

/**
 * Verifies that the standard migration is still working.
 *///from w w w. j  a va  2 s  . c  o  m
@Test
public final void verifyStandardMigration() {
    // Create the Flyway instance
    Flyway cut = new Flyway();

    // Point it to the database
    databasePath = "dbmigration" + System.nanoTime();
    cut.setDataSource("jdbc:h2:file:./target/" + databasePath, "sa", null);

    cut.setValidateOnMigrate(true);
    cut.setInitOnMigrate(true);
    cut.setInitVersion("0");

    // Start the migration
    int migrations = cut.migrate();

    assertThat("", migrations, is(2));

    try {
        Thread.sleep(SLEEP_TIME);
    } catch (InterruptedException e) {
        // Not expected
    }

    MigrationInfoService migrationInfoService = cut.info();
    assertThat("", migrationInfoService.pending().length, is(0));
}

From source file:com.snaker.ocr.TesseractOCR.java

@Override
public String recognize(byte[] image) throws OCRException {
    if (tessExecutable == null) {
        tessExecutable = getDefaultTessExecutable();
    }/*from  w  ww . j  a va2  s  .  com*/

    File source = null;
    File dest = null;
    try {
        String prefix = System.nanoTime() + "";
        source = File.createTempFile(prefix, ".jpg");
        DataOutputStream dos = new DataOutputStream(new FileOutputStream(source));
        dos.write(image);
        dos.flush();
        dos.close();
        String sourceFileName = source.getAbsolutePath();
        Process p = Runtime.getRuntime().exec(String.format("%s %s %s -l eng nobatch digits", tessExecutable,
                sourceFileName, sourceFileName));
        String destFileName = sourceFileName + ".txt";
        dest = new File(destFileName);
        int result = p.waitFor();
        if (result == 0) {
            BufferedReader in = new BufferedReader(new FileReader(dest));
            StringBuilder sb = new StringBuilder();
            String str;
            while ((str = in.readLine()) != null) {
                sb.append(str).append("\n");
            }
            in.close();
            return sb.toString().trim();
        } else {
            String msg;
            switch (result) {
            case 1:
                msg = "Errors accessing files. There may be spaces in your image's filename.";
                break;
            case 29:
                msg = "Cannot recognize the image or its selected region.";
                break;
            case 31:
                msg = "Unsupported image format.";
                break;
            default:
                msg = "Errors occurred.";
            }
            throw new OCRException(msg);
        }
    } catch (IOException e) {
        throw new OCRException("recognize failed", e);
    } catch (InterruptedException e) {
        logger.error("interrupted", e);
    } finally {
        if (source != null) {
            source.delete();
        }
        if (dest != null) {
            dest.delete();
        }
    }
    return null;
}

From source file:com.github.jmabuin.blaspark.solvers.JacobiSolver.java

/**
 * We are going to perform Ax = b where A is the input matrix. x is the output vector and b is the input vector
 * @param matrix The input matrix A//from   www . j  a  v  a  2 s. c  o  m
 * @param inputVector The input vector b
 * @param outputVector The output vector x
 * @param numIterations The max number of iterations to perform
 * @return The solution vector
 */
public static DenseVector solve(DistributedMatrix matrix, DenseVector inputVector, DenseVector outputVector,
        long numIterations, JavaSparkContext jsc) {

    long start = System.nanoTime();

    //Jacobi Method as shown in the example from https://en.wikipedia.org/wiki/Jacobi_method

    long k = 0;
    boolean stop = false;
    int i = 0;
    double result = 0.0;

    //Initial solution
    DenseVector x1;// = Vectors.zeros(inputVector.size()).toDense();
    double[] x1Values = new double[inputVector.size()];

    DenseVector x2 = Vectors.zeros(inputVector.size()).toDense();
    DenseVector res = Vectors.zeros(inputVector.size()).toDense();

    DistributedMatrix LU;
    DistributedMatrix Dinv;
    DistributedMatrix T = null;

    DenseVector C = Vectors.zeros(inputVector.size()).toDense();

    /*if(!isDiagonallyDominant(A,M,N,nz)){
       fprintf(stderr, "[%s] The matrix is not diagonally dominant\n",__func__);
       //return 0;
    }*/

    LU = OtherOperations.GetLU(matrix, jsc);

    Dinv = OtherOperations.GetD(matrix, true, jsc);

    for (i = 0; i < x1Values.length; i++) {
        x1Values[i] = 1.0;
    }

    x1 = new DenseVector(x1Values);
    //T=-D^{-1}(L+U)
    T = L3.DGEMM(-1.0, Dinv, LU, 0.0, T, jsc);

    //C=D^{-1}B
    C = L2.DGEMV(1.0, Dinv, inputVector, 0.0, C, jsc);

    long maxIterations = inputVector.size() * 2;

    if (numIterations != 0) {
        maxIterations = numIterations;
    }

    while (!stop) {

        // x^{(1)}= Tx^{(0)}+C
        //x2 = T*x1
        x2 = L2.DGEMV(1.0, T, x1, 0.0, x2, jsc);

        //x2 = x2+C
        BLAS.axpy(1.0, C, x2);

        //res = A*x - b
        res = inputVector.copy();
        L2.DGEMV(1.0, matrix, x2, -1.0, res, jsc);

        result = L1.vectorSumElements(res);

        if ((Math.abs(result) <= EPSILON) || (k == maxIterations)) {
            //fprintf(stderr,"Sum vector res is %lg\n",result);
            stop = true;
        }

        x1 = x2.copy();

        k++;
    }

    outputVector = x2.copy();

    long end = System.nanoTime();

    LOG.warn("Total time in solve system is: " + (end - start) / 1e9 + " and " + k + " iterations.");

    return outputVector;

}

From source file:ispok.bo.Admin.java

public void setPassword(String password) {
    this.salt = hashProvider.computeHash(System.nanoTime() + "");
    this.password = hashProvider.computeHash(password + salt);
}

From source file:Random64.java

public Random64() {
    super();
    setSeed(System.nanoTime());
}

From source file:org.jimsey.project.sswt.service.Ping.java

public long ping() {
    return System.nanoTime();

}

From source file:com.ebay.jetstream.event.processor.esper.raw.EsperTest.java

protected static void doSendAggrEvent(EPRuntime runtime, long workerId, Map<String, ? extends Object> map) {
    runtime.sendEvent(new CurrentTimeEvent(System.nanoTime() / 1000));
    runtime.sendEvent(map, "EsperTestAggregationEvent");

    EPOnDemandQueryResult result = runtime
            .executeQuery("SELECT workerId, SUM(V) AS RESULT, guid FROM SW GROUP BY workerId, guid");

    for (EventBean row : result.getArray()) {
        Long receivedWorkerId = (Long) row.get("workerId");
        if (receivedWorkerId != workerId)
            continue;
        Integer guid = (Integer) row.get("guid");
        Double aggregationValue = (Double) row.get("RESULT");
        System.out.println("guid=" + guid + ", RESULT=" + aggregationValue); //KEEPME
        m_aggregationResults.put(guid, aggregationValue);
        MapEventBean outMap = (MapEventBean) row;
        runtime.sendEvent(outMap.getProperties(), "OutputEvent");
    }// w  w w.j av  a2 s. c om

    EPOnDemandQueryResult resultAvg = runtime
            .executeQuery("SELECT workerId, AVG(V) AS RESULT, guid FROM SW GROUP BY workerId, guid");

    for (EventBean row : resultAvg.getArray()) {
        Long receivedWorkerId = (Long) row.get("workerId");
        if (receivedWorkerId != workerId)
            continue;
        Integer guid = (Integer) row.get("guid");
        Double aggregationValue = (Double) row.get("RESULT");
        System.out.println("guid=" + guid + ", RESULT=" + aggregationValue); //KEEPME
        m_aggregationAvgResults.put(guid, aggregationValue);
        MapEventBean outMap = (MapEventBean) row;
        runtime.sendEvent(outMap.getProperties(), "OutputEvent");
    }

    // it has to go last
    runtime.route(map, "CleanupWindowEvent");

}

From source file:at.tuwien.minimee.migration.runners.DefaultRunner.java

public RunInfo run() {
    RunInfo r = new RunInfo();

    log.debug("running tool: " + command);
    CommandExecutor cmdExecutor = new CommandExecutor();
    if (workingDir != null) {
        cmdExecutor.setWorkingDirectory(workingDir);
    }/*ww  w  .j  a v a 2s. com*/
    long startTime = System.nanoTime();
    try {
        int exitStatus = cmdExecutor.runCommand(command);
        r.setSuccess(exitStatus == 0);
        r.setReport(cmdExecutor.getCommandError());

        if (r.isSuccess() && "".equals(r.getReport())) {
            String report = cmdExecutor.getCommandOutput();
            if ("".equals(report)) {
                r.setReport("Successfully executed command.");
            } else {
                r.setReport(report);
            }
        } else if (!r.isSuccess() && "".equals(r.getReport())) {
            r.setReport("Failed to execute command.");
        }
    } catch (Exception e) {
        r.setSuccess(false);
        log.error(e.getMessage(), e);
        // For security reasons(!!) we do not provide very detailed information to the client here.
        r.setReport("An error occured while running the requested command on the server.");
        return r;
    }
    long elapsedTime = System.nanoTime() - startTime;
    r.setElapsedTimeMS(elapsedTime / 1000000);
    return r;
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.aop.MethodLogger.java

public static long startTimer() {
    long start_time = System.nanoTime();
    return start_time;
}

From source file:io.kahu.hawaii.util.call.statistics.RequestStatistic.java

public void startCallback() {
    this.startCallbackNano = System.nanoTime();
}