Tabnine Logo
System.nanoTime
Code IndexAdd Tabnine to your IDE (free)

How to use
nanoTime
method
in
java.lang.System

Best Java code snippets using java.lang.System.nanoTime (Showing top 20 results out of 36,252)

origin: google/guava

/** Calls {@link System#nanoTime()}. */
@SuppressWarnings("GoodTime") // reading system time without TimeSource
static long systemNanoTime() {
 return System.nanoTime();
}
origin: google/guava

/**
 * Returns System.nanoTime() unless the timeout has already elapsed. Returns 0L if and only if the
 * timeout has already elapsed.
 */
private static long initNanoTime(long timeoutNanos) {
 if (timeoutNanos <= 0L) {
  return 0L;
 } else {
  long startTime = System.nanoTime();
  return (startTime == 0L) ? 1L : startTime;
 }
}
origin: google/guava

/**
 * Returns the remaining nanos until the given timeout, or 0L if the timeout has already elapsed.
 * Caller must have previously sanitized timeoutNanos using toSafeNanos.
 */
private static long remainingNanos(long startTime, long timeoutNanos) {
 // assert timeoutNanos == 0L || startTime != 0L;
 // TODO : NOT CORRECT, BUT TESTS PASS ANYWAYS!
 // if (true) return timeoutNanos;
 // ONLY 2 TESTS FAIL IF WE DO:
 // if (true) return 0;
 return (timeoutNanos <= 0L) ? 0L : timeoutNanos - (System.nanoTime() - startTime);
}
origin: stackoverflow.com

 long startTime = System.nanoTime();
methodToTime();
long endTime = System.nanoTime();

long duration = (endTime - startTime);  //divide by 1000000 to get milliseconds.
origin: ReactiveX/RxJava

long now() {
  return System.nanoTime();
}
origin: square/okhttp

private void printEvent(String name) {
 long nowNanos = System.nanoTime();
 if (name.equals("callStart")) {
  callStartNanos = nowNanos;
 }
 long elapsedNanos = nowNanos - callStartNanos;
 System.out.printf("%.3f %s%n", elapsedNanos / 1000000000d, name);
}
origin: square/okhttp

@Override public void onOpen(WebSocket webSocket, Response response) {
 System.out.println("Executing test case " + number + "/" + count);
 startNanos.set(System.nanoTime());
}
origin: square/okhttp

 @Override public Response intercept(Chain chain) throws IOException {
  long t1 = System.nanoTime();
  Request request = chain.request();
  logger.info(String.format("Sending request %s on %s%n%s",
    request.url(), chain.connection(), request.headers()));
  Response response = chain.proceed(request);
  long t2 = System.nanoTime();
  logger.info(String.format("Received response for %s in %.1fms%n%s",
    request.url(), (t2 - t1) / 1e6d, response.headers()));
  return response;
 }
}
origin: square/okhttp

private void logWithTime(String message) {
 long timeMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
 logger.log("[" + timeMs + " ms] " + message);
}
origin: square/okhttp

 @Override public EventListener create(Call call) {
  long callId = nextCallId.getAndIncrement();
  System.out.printf("%04d %s%n", callId, call.request().url());
  return new PrintingEventListener(callId, System.nanoTime());
 }
};
origin: ReactiveX/RxJava

private static int randomIntFrom0to100() {
  // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml
  long x = System.nanoTime();
  x ^= (x << 21);
  x ^= (x >>> 35);
  x ^= (x << 4);
  return Math.abs((int) x % 100);
}
origin: ReactiveX/RxJava

private static int randomIntFrom0to(int max) {
  // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml
  long x = System.nanoTime();
  x ^= (x << 21);
  x ^= (x >>> 35);
  x ^= (x << 4);
  return Math.abs((int) x % max);
}
origin: ReactiveX/RxJava

private static int randomIntFrom0to100() {
  // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml
  long x = System.nanoTime();
  x ^= (x << 21);
  x ^= (x >>> 35);
  x ^= (x << 4);
  return Math.abs((int) x % 100);
}
origin: ReactiveX/RxJava

private static int randomIntFrom0to(int max) {
  // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml
  long x = System.nanoTime();
  x ^= (x << 21);
  x ^= (x >>> 35);
  x ^= (x << 4);
  return Math.abs((int) x % max);
}
origin: google/guava

/**
 * Returns the number of milliseconds since time given by startNanoTime, which must have been
 * previously returned from a call to {@link System.nanoTime()}.
 */
long millisElapsedSince(long startNanoTime) {
 return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime);
}
origin: square/okhttp

@Override
public void callStart(Call call) {
 startNs = System.nanoTime();
 logWithTime("callStart: " + call.request());
}
origin: google/guava

@Override
public void run() {
 startTime = System.nanoTime();
 try {
  future.get(timeout, unit);
 } catch (Exception e) {
  // nothing
  exception = e;
 } finally {
  timeSpentBlocked = System.nanoTime() - startTime;
 }
}
origin: ReactiveX/RxJava

@Override
public void onComplete() {
  System.out.println("onComplete");
  completeTime.set(System.nanoTime());
  completedLatch.countDown();
}
origin: ReactiveX/RxJava

@Override
public void onComplete() {
  System.out.println("onComplete");
  completeTime.set(System.nanoTime());
  completedLatch.countDown();
}
origin: google/guava

protected void runTestProfiled() throws Throwable {
 long t0 = System.nanoTime();
 try {
  super.runTest();
 } finally {
  long elapsedMillis = (System.nanoTime() - t0) / (1000L * 1000L);
  if (elapsedMillis >= profileThreshold)
   System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
 }
}
java.langSystemnanoTime

Javadoc

Returns the current timestamp of the most precise timer available on the local system, in nanoseconds. Equivalent to Linux's CLOCK_MONOTONIC.

This timestamp should only be used to measure a duration by comparing it against another timestamp on the same device. Values returned by this method do not have a defined correspondence to wall clock times; the zero value is typically whenever the device last booted. Use #currentTimeMillis if you want to know what time it is.

Popular methods of System

  • currentTimeMillis
    Returns the current time in milliseconds. Note that while the unit of time of the return value is a
  • getProperty
    Returns the value of a particular system property. The defaultValue will be returned if no such prop
  • arraycopy
  • exit
  • setProperty
    Sets the value of a particular system property.
  • getenv
    Returns the value of the environment variable with the given name, or null if no such variable exist
  • getProperties
    Returns the system properties. Note that this is not a copy, so that changes made to the returned Pr
  • identityHashCode
    Returns an integer hash code for the parameter. The hash code returned is the same one that would be
  • getSecurityManager
    Gets the system security interface.
  • gc
    Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a h
  • lineSeparator
    Returns the system's line separator. On Android, this is "\n". The value comes from the value of the
  • clearProperty
    Removes a specific system property.
  • lineSeparator,
  • clearProperty,
  • setOut,
  • setErr,
  • console,
  • loadLibrary,
  • load,
  • setSecurityManager,
  • mapLibraryName

Popular in Java

  • Finding current android device location
  • addToBackStack (FragmentTransaction)
  • getSystemService (Context)
  • setContentView (Activity)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JPanel (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now