From 4c51d9f6d6721f92bc1c8b4de3daa381ff63e792 Mon Sep 17 00:00:00 2001 From: Dominic Egginton Date: Mon, 4 May 2020 14:21:10 +0100 Subject: [PATCH] doc: add basic documentation for install and usage --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 68877b3..cf982e3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,49 @@ # Nanoseconds + ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/dominicegginton/Nanoseconds/CI?label=CI) ![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/dominicegginton/Nanoseconds?include_prereleases&label=release) + > 🕐 Simple high resolution timing for Swift +Nanoseconds is a wrapper around `DispatchTime.now()` providing you with timestamp with nanosecond accuracy. + +## Key Features + +- High resolution time stamp +- Built-in operators overloads +- Useful extensions for unit conversion +- Linux compatible + +## Install + +Install via the [**Swift Package Manger**](https://swift.org/package-manager/) by declaring **Spinner** as a dependency in your `Package.swift`: + +``` swift +.package(url: "https://github.com/dominicegginton/Nanoseconds", from: "0.0.1") +``` + +Remember to add **Spinner** to your target as a dependency. + +## Usage + +Creating high resolution timestamps with nanosecond accuracy is easy: + +``` swift +let foo = Nanoseconds() +``` + +Use built-in operators overloads to calculate a [**TimeInterval**](https://developer.apple.com/documentation/foundation/timeinterval): + +``` swift +let start = Nanoseconds() +sleep(1) +let end = Nanoseconds() +let duration = end - start +print(duration) //=> 1004222113.0 +``` + +To convert high resolutions [**TimeInterval**](https://developer.apple.com/documentation/foundation/timeinterval) objects from nanosecond accuracy use a provided extention: + +``` swift +print(duration.milliseconds) //=> 1004.22211 +print(duration.seconds) //=> 1.004222113 +```