Java Code Examples for java.util.concurrent.TimeUnit#NANOSECONDS

The following examples show how to use java.util.concurrent.TimeUnit#NANOSECONDS . 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: Moment.java    From Time4A with Apache License 2.0 5 votes vote down vote up
@Override
public TimeUnit getValue(Moment context) {

    int f = context.getNanosecond();

    if (f != 0) {
        if ((f % MIO) == 0) {
            return TimeUnit.MILLISECONDS;
        } else if ((f % 1000) == 0) {
            return TimeUnit.MICROSECONDS;
        } else {
            return TimeUnit.NANOSECONDS;
        }
    }

    long secs = context.posixTime;

    if (MathUtils.floorModulo(secs, 86400) == 0) {
        return TimeUnit.DAYS;
    } else if (MathUtils.floorModulo(secs, 3600) == 0) {
        return TimeUnit.HOURS;
    } else if (MathUtils.floorModulo(secs, 60) == 0) {
        return TimeUnit.MINUTES;
    } else {
        return TimeUnit.SECONDS;
    }

}
 
Example 2
Source File: TagContextBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Get the current tag context. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public TagContext getCurrentTagContext(Data data) {
  return data.tagger.getCurrentTagContext();
}
 
Example 3
Source File: AWSXRayRecorderBenchmark.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.All)
@Fork(value=1)
@Warmup(iterations = 20)
@Measurement(iterations = 20)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Subsegment beginSubsegmentDummyParentBenchmark(DummyPopulatedRecorderState state) {
    return state.recorder.beginSubsegment(SUBSEGMENT_NAME);
}
 
Example 4
Source File: TimeoutBudget.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public static TimeoutBudget ofDuration(final Duration duration) {
    final long ms = duration.toMillis();
    if (ms < 0) {
        return new TimeoutBudget(duration.toNanos(), TimeUnit.NANOSECONDS);
    } else {
        return new TimeoutBudget(ms, TimeUnit.MILLISECONDS);
    }
}
 
Example 5
Source File: BasicOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Get current trace span. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span getCurrentSpan(Data data) {
  return data.tracer.getCurrentSpan();
}
 
Example 6
Source File: ResumableApiTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Verify that tryResume(TransctionId, long, TimeUnit) waits the full time and returns the expected
 *  value. 
 * 
 * @param txId The transaction ID to attempt to resume. 
 * @param timeValue A tryResume argument.
 * @param unit A tryResume argument.
 * @param expectedResult The expected result from tryResume.
 */
private void verifyTryResumeWaits(TransactionId txId, long timeValue, TimeUnit unit, boolean expectedResult) {
  Object[] tmp = tryResume(txId, timeValue, unit);
  boolean result = (Boolean)tmp[0];
  long duration = (Long)tmp[1];

  // verify the wait
  long expectedWaitMs = timeValue;
  if (unit == TimeUnit.SECONDS) {
    expectedWaitMs = timeValue * 1000;
  } else if (unit == TimeUnit.MICROSECONDS) {
    expectedWaitMs = timeValue / 1000;
  } else if (unit == TimeUnit.NANOSECONDS) {
    expectedWaitMs = timeValue / 1000000;
  } else if (unit == TimeUnit.MILLISECONDS){
    // already set
  } else {
    throw new TestException("Unknown TimeUnit " + unit);
  }
  if (duration < expectedWaitMs) {
    throw new TestException("Expected tryResume(" + txId + ", " + timeValue + ", " + unit + ") to wait for " +
        expectedWaitMs + "ms but it took " + duration + "ms");
  }
  if (result != expectedResult) {
    throw new TestException("Expected tryResume(" + txId + ", " + timeValue + ", " + unit + ") to return " +
        expectedResult + ", but it returned " + result);
  }
}
 
Example 7
Source File: TimeFormatBenchmark.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public String fixedDateFormatReuseCharArray(final BufferState state) {
    final int len = fixedDateFormat.format(System.currentTimeMillis(), state.charArray, 0);
    return new String(state.charArray, 0, len);
}
 
Example 8
Source File: BasicOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Create a link. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Link createLink(Data data) {
  return Link.fromSpanContext(
      SpanContext.create(
          TraceId.fromBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0}),
          SpanId.fromBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 0}),
          TraceOptions.DEFAULT,
          TRACESTATE_DEFAULT),
      Link.Type.PARENT_LINKED_SPAN);
}
 
Example 9
Source File: Timeouts.java    From tascalate-concurrent with Apache License 2.0 5 votes vote down vote up
TimeMeasurment(Duration duration) {
    // Try to get value with best precision without throwing ArythmeticException due to overflow
    if (duration.compareTo(MAX_BY_NANOS) < 0) {
        amount = duration.toNanos();
        unit = TimeUnit.NANOSECONDS;
    } else if (duration.compareTo(MAX_BY_MILLIS) < 0) {
        amount = duration.toMillis();
        unit = TimeUnit.MILLISECONDS;
    } else {
        amount = duration.getSeconds();
        unit = TimeUnit.SECONDS; 
    }
}
 
Example 10
Source File: AWSXRayRecorderBenchmark.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.All)
@Fork(value=1)
@Warmup(iterations = 20)
@Measurement(iterations = 20)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void endSubsegmentDummyParentBenchmark(DummyPopulatedRecorderState state) {
    state.recorder.endSubsegment();
}
 
Example 11
Source File: KeepAliveEnforcerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void strikeOutBecauseNoOutstandingCalls() {
  KeepAliveEnforcer enforcer = new KeepAliveEnforcer(false, 0, TimeUnit.NANOSECONDS, ticker);
  enforcer.onTransportIdle();
  for (int i = 0; i < KeepAliveEnforcer.MAX_PING_STRIKES; i++) {
    assertThat(enforcer.pingAcceptable()).isTrue();
  }
  assertThat(enforcer.pingAcceptable()).isFalse();
}
 
Example 12
Source File: MaxExecutionTimeVerifier.java    From quickperf with Apache License 2.0 5 votes vote down vote up
private ExecutionTime buildMaxExpectedExecutionTimeFrom(ExpectMaxExecutionTime annotation) {
    long maxExpectedExecutionTimeInNanoSeconds =
              TimeUnit.HOURS.toNanos(annotation.hours())
            + TimeUnit.MINUTES.toNanos(annotation.minutes())
            + TimeUnit.SECONDS.toNanos(annotation.seconds())
            + TimeUnit.MILLISECONDS.toNanos(annotation.milliSeconds())
            + TimeUnit.MICROSECONDS.toNanos(annotation.microSeconds())
            + annotation.nanoSeconds();
    return new ExecutionTime(maxExpectedExecutionTimeInNanoSeconds
                           , TimeUnit.NANOSECONDS);
}
 
Example 13
Source File: StringEncodingBenchmark.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public byte[] iso8859_1Encoder() throws CharacterCodingException {
    final ByteBuffer buf = ENCODER_ISO8859_1.encode(CharBuffer.wrap(LOGMSG));
    return buf.array();
}
 
Example 14
Source File: PatternLayoutBenchmark.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public String serializableMDNoSpace() {
    return PATTERN_M_D_NOSPACE.toSerializable(EVENT);
}
 
Example 15
Source File: PatternLayoutBenchmark.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public String serializableD() {
    return PATTERN_D.toSerializable(EVENT);
}
 
Example 16
Source File: GaugeBenchmark.java    From client_java with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void prometheusSimpleGaugeSetBenchmark() {
  prometheusSimpleGauge.labels("test", "group").set(42); 
}
 
Example 17
Source File: UnboxBenchmark.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public StringBuilder boxShort() {
    return Unbox.box((short) 123);
}
 
Example 18
Source File: Benchmarking.java    From tutorials with MIT License 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void usingStringUtils_isNumericSpace(ExecutionPlan plan) {
    plan.validate(subject::usingStringUtils_isNumericSpace);
}
 
Example 19
Source File: GaugeBenchmark.java    From client_java with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void prometheusSimpleGaugeNoLabelsDecBenchmark() {
  prometheusSimpleGaugeNoLabels.dec(); 
}
 
Example 20
Source File: Configuration.java    From Flink-CEPplus with Apache License 2.0 votes vote down vote up
TimeUnit unit() { return TimeUnit.NANOSECONDS; }