-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add basic documentation for install and usage
- Loading branch information
1 parent
6255465
commit 4c51d9f
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |