The Time module benchmarks the overhead of Rumi'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.
Rumi 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.
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
Uses JNI to call native high-resolution clock:
Characteristics:
Highest resolution (typically nanosecond precision)
Slightly higher overhead due to JNI call
Wall-clock time (can go backwards on NTP adjustments)
Use When: You need highest resolution time and can afford JNI overhead
Uses pure Java implementation:
Characteristics:
Pure Java (no JNI overhead)
Lower overhead than native
Wall-clock time (can go backwards on NTP adjustments)
Resolution depends on JVM (typically microsecond precision)
Use When: You need wall-clock time with lower overhead
System.nanoTime()
Uses JVM's monotonic time source:
Characteristics:
Monotonic (never goes backwards)
NOT wall-clock time (arbitrary epoch)
Use When: You need to measure elapsed time or durations
Command-Line Parameters
Time source: native, epoch, or nano (default: native)
Number of concurrent threads (default: 1)
Running the Benchmark
Test Native Time
Example Output:
Test Epoch Time
Example Output:
Test System.nanoTime()
Example Output:
Test with Multiple Threads
Example Output:
Interpreting Results
The benchmark reports the average overhead per time acquisition in nanoseconds.
Typical Results (Linux x86-64)
Time Source
Single Thread
Multiple Threads
Resolution
Absolute Overhead:
All time sources have sub-40ns overhead
Overhead is negligible for most applications
Matters most in tight loops or very low latency paths
Contention:
Time acquisition overhead typically doesn't increase with thread count
Modern CPUs have per-core time sources
Use Case Selection:
Latency Tracking: Use native or epoch time for wall-clock timestamps
Duration Measurement: Use System.nanoTime() for elapsed time
Hot Paths: Use epoch time for balance of overhead and resolution
For Latency Measurement
Use wall-clock time (native or epoch) to timestamp events:
For Duration Measurement
Use System.nanoTime() for elapsed time:
For High-Frequency Calls
If time acquisition is in a critical path called millions of times per second, prefer epoch time:
System Properties
Property
Values
Description
Enable/disable native time (default: true)
Review AEP Module to see time usage in end-to-end benchmarks