Swiftpack.co - Package - dominicegginton/Nanoseconds
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

Nanoseconds

Simple high resolution timing for Swift

Key Features

  • High resolution time stamp
  • Built-in operators overloads
  • Useful extensions for unit conversion
  • Linux compatible

Install

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.

Documentation

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()
sleep(1)
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)

Github

link
Stars: 1

Releases

- 2021-01-07T10:23:39

Features

  • Breaking Change: renamed Nanoseconds object to Now (#3)

Documentation

  • better heading styles for documentation (a767f15d9421cb1cca4dd71d341b4d1401c6305f, 218c53a3c721bd49e29e1ccb3c70ee2623e653ff)
  • added documention for unit conversion timeinterval init methods (90b9d5eb8553f5b24b3bad211af28f07743eedd7)

0.1.1 - 2021-01-06T19:02:53

Fixed

  • fixed naming of microseconds conversion extention to the timeinterval object (b54f2ebd073b7048ab740c1ac2b95f2e4dc5f0bc, bc63f643de6c7102e7fbd5860102e2d4e3f47bf9)

Features

  • added unit conversion extention for nanoseconds to the timeinterval object (a6498f6c01be191e1e39f0b1a743f7631bf81617)

Maintenance

  • added tests for coversion of the timeinterval object (58dca92b0f30fb9fc2e906a364e6fc73c2db8bd6)

- 2021-01-06T18:15:35

Features

  • added timeinterval init mehtods to easy convert common time units (#2)

0.0.2 - 2020-10-03T17:20:04

0.0.1 - 2020-10-03T17:19:46