nanotime

Nanosecond-Resolution Time for R

Full 64-bit resolution date and time support with resolution up
to nanosecond granularity is provided, with easy transition to and from the
standard 'POSIXct' type.

Nanosecond Time Resolution for R

Motivation

R has excellent tools for dates and times. The Date and POSIXct classes (as well as the 'wide'
representation in POSIXlt) are versatile, and a lot of useful tooling has been built around them.

However, POSIXct is implemented as a double with fractional seconds since the epoch. Given the
53 bits accuracy, it leaves just a bit less than microsecond resolution. Which is good enough for
most things.

But more and more performance measurements, latency statistics, ... are now measured more finely,
and we need nanosecond resolution. For which commonly an integer64 is used to represent
nanoseconds since the epoch.

And while R does not have a native type for this, the bit64
package by Jens Oehlschlägel offers a performant one implemented as a
lightweight S3 class. So this package uses this integer64 class, along with two helper functions
for parsing and formatting, respectively, at nano-second resolution from the
RcppCCTZ package which wraps the
CCTZ library from Google. CCTZ is a modern C++11 library
extending the (C++11-native) chrono type.

Demo

See the included demo script nanosecondDelayExample.R
for a (completely simulated and hence made-up) study of network latency measured
in nanoseconds resulting in the figure below

Use with data.frame

This requires version 0.0.2 or later.

R> df <- data.frame(cbind(A=1:5, B=5:1), v=v)

Technical Details

The bit64 package (by
Jens Oehlschlägel) supplies the integer64 type used to store the
nanosecond resolution time as (positive or negative) offsets to the epoch of January 1, 1970. The
RcppCCTZ package supplies the formatting and
parsing routines based on the (modern C++) library CCTZ from
Google.

Status

The package is in the very early stages. Expect changes, maybe even breaking ones. But the package
has some tests, and code coverage.

See the issue tickets for an up to date list of potentially desirable, possibly planned, or at least discussed items.