Swiftpack.co -  Package - dominicegginton/Nanoseconds
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Simple high-resolution timing for Swift
.package(url: "https://github.com/dominicegginton/Nanoseconds.git", from: "1.1.1")

Nanoseconds proves high resolution time stamps for swift developers along with helpful tools to work with them.

Key Features

  • High resolution time stamp
  • Built-in operators overloads
  • Useful extensions for unit conversion
  • Covert time intervals to a human readable strings
  • Linux compatible


Install via the Swift Package Manger by declaring Nanoseconds as a dependency in your Package.swift:

.package(url: "https://github.com/dominicegginton/Nanoseconds", from: "1.0.0")

Remember to add Nanoseconds to your target as a dependency.


Creating Timestamps

Creating high resolution timestamps with nanosecond accuracy is easy, simply create a instant of Now struct

let foo = Now()

Creating Time Intervals

Use the built-in operators overloads to easily calculate and initialize TimeInterval:

let start = Now()
let end = Now()
let duration = end - start
print(duration)  //=> 1004222113.0

Convert Time Intervals from Nanoseconds to Other Time Units

To convert TimeInterval objects from nanosecond to a different unit simply use a provided extension:

  • nanoseconds
  • microseconds
  • milliseconds
  • seconds
  • minutes
  • hours
print(duration.milliseconds)  //=> 1004.22211
print(duration.seconds)  //=> 1.004222113

Create TimeIntervals Objects from any time unit

Use a provided init method to create a TimeInterval object from any time unit

let duration = TimeInterval(seconds: 8)

Covert TimeIntervals Objects to human readable strings

Use the provided timeString variable to convert TimeInterval objects into a human readable format:

let duration = TimeInterval(hours: 1) + TimeInterval(seconds: 120)
print(duration.timeString)  //=> 1h 1m 30s


Stars: 3
Last commit: 5 days ago

Release Notes

2 weeks ago


  • added documentation for converting TimeInterval objects to human readable strings (d874aa99470f12f38a1b9315c0a481adfaacc8b5)
  • introducing a cover image and logo for Nanoseconds (f4a266d9e1be92b232ab893e9c766ab2374b68ac)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco