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:com.tbodt.trp.TheRapidPermuter.java

private static void doCommand(String command) {
    long before = System.nanoTime();

    // The most important line in the program!
    CommandProcessor.processCommand(command).ifPresent(data -> data.forEach(System.out::println));

    long after = System.nanoTime();
    if (cmd.hasOption('t'))
        System.out.println((after - before) / 1_000_000 + " ms");
    System.gc(); // why not?
}

From source file:jp.primecloud.auto.common.interceptor.TraceInterceptor.java

/**
 * {@inheritDoc}/* www. j a  v a2 s.  c o m*/
 */
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    if (!log.isDebugEnabled()) {
        return invocation.proceed();
    }

    // ?
    log.debug(startLog(invocation));

    // ?
    long startTime = System.nanoTime();

    // ?
    indents.set(indents.get() + 1);

    try {
        return invocation.proceed();
    } finally {
        // ?
        indents.set(indents.get() - 1);

        // ?
        long stopTime = System.nanoTime();

        // ?
        log.debug(stopLog(invocation, stopTime - startTime));
    }
}

From source file:com.clican.pluto.dataprocess.engine.processes.MvelExecProcessor.java

public void process(ProcessorContext context) throws DataProcessException {
    long nanoSeconds = System.nanoTime();
    logger.trace("start processing mvel expression(" + this.getId() + ") ...");
    if (StringUtils.isEmpty(mvelExpression)) {
        throw new DataProcessException("The MVEL Expression cannt be null");
    }//from w  w  w  .  j a  va2s  . c  o  m
    Map<String, Object> map = new HashMap<String, Object>();
    for (String attributeName : context.getAttributeNames()) {
        map.put(attributeName, context.getAttribute(attributeName));
    }
    map.put("context", context);
    Object obj = MVEL.eval(mvelExpression, map);
    if (StringUtils.isNotEmpty(resultName)) {
        context.setAttribute(resultName, obj);
    }
    logger.trace("end processing mvel expression(" + this.getId() + "), time consumed: "
            + (System.nanoTime() - nanoSeconds) / 1000000 + " ms");
}

From source file:ddf.security.encryption.impl.EncryptionServiceImplTest.java

@Test
public void testBadSetup() throws Exception {
    System.setProperty("ddf.home", ddfHome.getAbsolutePath() + System.nanoTime());
    final String unencryptedPassword = "protect";

    final EncryptionServiceImpl encryptionService = new EncryptionServiceImpl();

    final String encryptedPassword = encryptionService.encrypt(unencryptedPassword);
    assertEquals(encryptedPassword, unencryptedPassword);

    final String decryptedPassword = encryptionService.decrypt(encryptedPassword);
    assertEquals(decryptedPassword, encryptedPassword);

    final String wrappedPassword = "ENC(" + unencryptedPassword + ")";
    final String unWrappedDecryptedPassword = encryptionService.decryptValue(wrappedPassword);

    assertEquals(unWrappedDecryptedPassword, unencryptedPassword);
}

From source file:dtu.ds.warnme.utils.RandomUtils.java

public static UserEntity randomUser() throws Exception {
    UserEntity user = new UserEntity();
    user.setUsername("user" + System.nanoTime());
    user.setPassword(SecurityUtils.hashSHA512Base64("pass" + System.nanoTime()));
    user.setEmail("email" + System.nanoTime() + "@email.com");
    return user;/*ww  w  .  j av a2  s.  c  om*/
}

From source file:com.netflix.scheduledactions.Execution.java

@JsonCreator
public Execution(@JsonProperty("executorId") String executorId,
        @JsonProperty("actionInstanceId") String actionInstanceId) {
    this.executorId = executorId;
    this.actionInstanceId = actionInstanceId;
    this.createdTime = System.nanoTime(); // Used just for comparing
}

From source file:dk.statsbiblioteket.netark.dvenabler.wrapper.SortedDocValuesWrapper.java

public SortedDocValuesWrapper(AtomicReader reader, DVConfig field) throws IOException {
    this.reader = reader;
    this.field = field;
    FIELDS = new HashSet<>(Arrays.asList(field.getName()));
    log.info("Creating map for SortedDocValues for field '" + field + "'");
    long startTime = System.nanoTime();
    values = fill();//from   w w  w.j a v  a  2 s  .c  o  m
    tracker = new ProgressTracker(field.getName(), log, reader.maxDoc());
    log.info("Finished creating SortedDocValues with " + values.size() + " unique values for " + reader.maxDoc()
            + " docs for field '" + field + "' in " + ((System.nanoTime() - startTime) / 1000000 / 1000)
            + "ms");
}

From source file:com.github.jinahya.codec.BossVsEngineerTestNanoTimeDecode.java

private static long decodeLikeABoss(final byte[] encoded) {
    final long start = System.nanoTime();
    new HexDecoder().decodeLikeABoss(encoded);
    return System.nanoTime() - start;
}

From source file:com.github.jinahya.codec.BossVsEngineerTestNanoTimeEncode.java

private static long encodeLikeABoss(final byte[] decoded) {
    final long start = System.nanoTime();
    new HexEncoder().encodeLikeABoss(decoded);
    return System.nanoTime() - start;
}

From source file:com.yahoo.ycsb.db.RedisClient.java

public static String compressWithLog(String st) {
    // System.out.println("compress");
    // System.out.println(st.substring(0, 20));
    long start_time = System.nanoTime();
    String ret = compress(st);/*from  w ww. j  a  va  2s .  c o  m*/
    try {
        long end_time = System.nanoTime();
        long time = end_time - start_time;
        BufferedWriter bw = new BufferedWriter(new FileWriter("compress_time.txt", true));
        bw.write("" + time);
        bw.newLine();
        bw.flush();
        BufferedWriter bw2 = new BufferedWriter(new FileWriter("compress_rate.txt", true));
        double r1 = ret.length();
        double r2 = st.length();
        double r = r1 / r2;
        bw2.write("" + r);
        bw2.newLine();
        bw2.flush();
    } catch (Exception e) {
    }
    // System.out.println("compressed");
    // System.out.println(ret.substring(0, 20));
    return ret;
}