The Time module benchmarks the overhead of X Platform's time acquisition APIs. Time acquisition is a critical operation in high-performance systems, and this benchmark helps quantify the cost of different time sources.
Overview
X Platform provides multiple time sources optimized for different use cases:
Native Time: Uses native (JNI) calls for high-resolution wall-clock time
Epoch Time: Uses pure Java implementation for wall-clock time
System.nanoTime(): JVM's monotonic time source
This benchmark measures the overhead (in nanoseconds) of acquiring time from each source.
Test Program
Class: com.neeve.perf.time.Benchmark
The benchmark:
Warms up with 10,000 time acquisitions
Measures 100,000,000 time acquisitions
Reports average overhead per call in nanoseconds
Supports concurrent execution across multiple threads
# Extract distribution
tar xvf nvx-perf-time-{version}-dist-linux-x86-64.tar.gz
cd nvx-perf-time-{version}
# Run benchmark with native time
$JAVA_HOME/bin/java -cp "libs/*" com.neeve.perf.time.Benchmark --mode native
USING UtlTime.now() [NATIVE TIME IS ENABLED]
[tid 10] Time overhead is 37 nanos
[tid 11] Time overhead is 36 nanos
[tid 12] Time overhead is 38 nanos
[tid 13] Time overhead is 35 nanos
// Timestamp incoming message
long receiveTime = UtlTime.now();
// Process message...
// Timestamp outgoing message
long sendTime = UtlTime.now();
// Calculate latency
long latency = sendTime - receiveTime;
// Start timing
long startNanos = System.nanoTime();
// Do work...
// Calculate duration
long durationNanos = System.nanoTime() - startNanos;
// Configure at startup
System.setProperty("nv.time.usenative", "false");
// In critical path
long timestamp = UtlTime.now(); // Uses epoch time (lower overhead)