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

The following are Jave code examples for showing how to use NANOSECONDS of the java.util.concurrent.TimeUnit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: java-benchmark   File: DeserJsoniter.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        iter.reset(testJSON);
        bh.consume(iter.read(typeLiteral));
    }
}
 
Example 2
Project: java-benchmark   File: SerFastjson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        SerializeWriter writer = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(writer, serializeConfig);
        serializer.write(testObject);
        writer.writeToEx(byteArrayOutputStream, IOUtils.UTF8);
        serializer.close();
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 3
Project: java-benchmark   File: DeserPb.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        bh.consume(Pb.PbTestObject.parseFrom(testData));
    }
}
 
Example 4
Project: java-benchmark   File: SerThrift.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws TException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        testObject.write(protocol);
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 5
Project: java-benchmark   File: SerJackson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        objectMapper.writeValue(byteArrayOutputStream, testObject);
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 6
Project: datarouter   File: Duration.java   Source Code and License Vote up 5 votes
@Test
public void parserAndtoStringTest(){
	Duration duration = new Duration(3, TimeUnit.DAYS);
	AssertJUnit.assertEquals("3d", duration.toString());
	duration = new Duration("1d2h65m15s");
	AssertJUnit.assertEquals("1d3h5m15s", duration.toString());
	duration = new Duration("2h1d65m15s");
	AssertJUnit.assertEquals("1d3h5m15s", duration.toString());
	duration = new Duration("15s");
	AssertJUnit.assertEquals(15, duration.toSecond());
	AssertJUnit.assertEquals("15s", duration.toString());
	duration = new Duration("100000d5s123ms");
	AssertJUnit.assertEquals("100000d5s123ms", duration.toString());
	duration = new Duration("100000 d 5s 123 ms");
	AssertJUnit.assertEquals("100000d5s123ms", duration.toString());
	duration = new Duration("48h");
	AssertJUnit.assertEquals("2d", duration.toString());
	duration = new Duration("0");
	AssertJUnit.assertEquals("0ms", duration.toString());
	duration = new Duration("max");
	AssertJUnit.assertEquals(MAX_VALUE.toString(TimeUnit.NANOSECONDS), duration.toString(TimeUnit.NANOSECONDS));
	duration = new Duration("1d1d");
	AssertJUnit.assertEquals("2d", duration.toString());
	duration = new Duration("4ms1us");
	AssertJUnit.assertEquals("4ms1us", duration.toString(TimeUnit.MICROSECONDS));
	duration = new Duration(1234, TimeUnit.NANOSECONDS);
	AssertJUnit.assertEquals("1us", duration.toString(TimeUnit.MICROSECONDS));
	AssertJUnit.assertEquals("1us", duration.toString(TimeUnit.NANOSECONDS));
}
 
Example 7
Project: java-benchmark   File: DeserDslJson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        reader.reset();
        reader.read();
        reader.getNextToken();
        TestObject obj = new TestObject();
        ExternalSerialization.deserialize(obj, reader);
        bh.consume(obj);
    }
}
 
Example 8
Project: java-benchmark   File: DeserJackson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        bh.consume(objectMapper.readValue(testJSON, typeReference));
    }
}
 
Example 9
Project: ProtocolSupportPocketStuff   File: ExpiringMap.java   Source Code and License Vote up 5 votes
private V load(K key) {
  if (entryLoader == null && expiringEntryLoader == null)
    return null;

  writeLock.lock();
  try {
    // Double check for entry
    ExpiringEntry<K, V> entry = getEntry(key);
    if (entry != null)
      return entry.getValue();

    if (entryLoader != null) {
      V value = entryLoader.load(key);
      put(key, value);
      return value;
    } else {
      ExpiringValue<? extends V> expiringValue = expiringEntryLoader.load(key);
      if (expiringValue == null) {
        put(key, null);
        return null;
      } else {
        long duration = expiringValue.getTimeUnit() == null ? expirationNanos.get() : expiringValue.getDuration();
        TimeUnit timeUnit = expiringValue.getTimeUnit() == null ? TimeUnit.NANOSECONDS : expiringValue.getTimeUnit();
        put(key, expiringValue.getValue(), expiringValue.getExpirationPolicy() == null ? expirationPolicy.get()
            : expiringValue.getExpirationPolicy(), duration, timeUnit);
        return expiringValue.getValue();
      }
    }
  } finally {
    writeLock.unlock();
  }
}
 
Example 10
Project: java-benchmark   File: SerPb.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        testObject.writeTo(byteArrayOutputStream);
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 11
Project: java-benchmark   File: DeserPb.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        bh.consume(Pb.PbTestReadObject.parseFrom(testData));
    }
}
 
Example 12
Project: java-benchmark   File: DeserThrift.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws TException {
    for (int i = 0; i < 1000; i++) {
        ThriftTestObject obj = new ThriftTestObject();
        deserializer.deserialize(testObject, testData);
        bh.consume(obj);
    }
}
 
Example 13
Project: java-benchmark   File: DeserJsoniter.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        iter.reset(testJSON);
        bh.consume(iter.read(typeLiteral));
    }
}
 
Example 14
Project: java-benchmark   File: SerThrift.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws TException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        testObject.write(protocol);
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 15
Project: java-benchmark   File: DeserJackson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        bh.consume(objectMapper.readValue(testJSON, typeReference));
    }
}
 
Example 16
Project: java-benchmark   File: SerJackson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        objectMapper.writeValue(byteArrayOutputStream, testObject);
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 17
Project: java-benchmark   File: DeserJsoniter.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        iter.reset(testJSON);
        bh.consume(iter.read(typeLiteral));
    }
}
 
Example 18
Project: java-benchmark   File: SerFastjson.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        SerializeWriter writer = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(writer, serializeConfig);
        serializer.write(testObject);
        writer.writeToEx(byteArrayOutputStream, IOUtils.UTF8);
        serializer.close();
        bh.consume(byteArrayOutputStream);
    }
}
 
Example 19
Project: java-benchmark   File: DeserPb.java   Source Code and License Vote up 5 votes
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void deser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        bh.consume(PbTestObect.PbTestObject.parseFrom(testData));
    }
}
 
Example 20
Project: feeyo-redisproxy   File: NameableExecutor.java   Source Code and License Vote up 4 votes
public NameableExecutor(String name, int size, BlockingQueue<Runnable> queue, ThreadFactory factory) {
    super(size, size, Long.MAX_VALUE, TimeUnit.NANOSECONDS, queue, factory);
    this.name = name;
}