Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 761569d

Browse files
fabianfettslashmo
andcommitted
Cleanup (#1)
Co-authored-by: Moritz Lang <[email protected]>
1 parent f2f3ebc commit 761569d

File tree

10 files changed

+426
-294
lines changed

10 files changed

+426
-294
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ on:
99

1010
jobs:
1111

12-
"sanity-Tests":
12+
"validity-Tests":
1313
runs-on: macOS-latest
1414
steps:
1515
- name: Checkout
1616
uses: actions/checkout@v2
1717
- name: Install swiftformat
1818
run: brew install swiftformat
19-
- name: Run sanity
20-
run: ./scripts/sanity.sh .
19+
- name: Run validity
20+
run: ./scripts/validity.sh .
2121

2222
"tuxOS-Tests":
2323
runs-on: ubuntu-latest
2424
strategy:
25+
fail-fast: false
2526
matrix:
2627
images:
2728
- swift:5.1
2829
- swift:5.2
29-
- swiftlang/swift:nightly-5.3-bionic
30+
- swift:5.3
3031
- swiftlang/swift:nightly-bionic
3132
container:
3233
image: ${{ matrix.images }}
@@ -51,11 +52,12 @@ jobs:
5152
"tuxOS-Performance-Tests":
5253
runs-on: ubuntu-latest
5354
strategy:
55+
fail-fast: false
5456
matrix:
5557
images:
5658
- swift:5.1
5759
- swift:5.2
58-
- swiftlang/swift:nightly-5.3-bionic
60+
- swift:5.3
5961
- swiftlang/swift:nightly-bionic
6062
container:
6163
image: ${{ matrix.images }}
@@ -68,11 +70,12 @@ jobs:
6870
"macOS-Tests":
6971
runs-on: macOS-latest
7072
strategy:
73+
fail-fast: false
7174
matrix:
7275
xcode:
7376
- Xcode_11.1.app
7477
- Xcode_11.6.app
75-
- Xcode_12.app
78+
- Xcode_12.2.app
7679
steps:
7780
- name: Checkout
7881
uses: actions/checkout@v2
@@ -92,11 +95,12 @@ jobs:
9295
"macOS-Performance-Tests":
9396
runs-on: macOS-latest
9497
strategy:
98+
fail-fast: false
9599
matrix:
96100
xcode:
97101
- Xcode_11.1.app
98102
- Xcode_11.6.app
99-
- Xcode_12.app
103+
- Xcode_12.2.app
100104
steps:
101105
- name: Checkout
102106
uses: actions/checkout@v2

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,82 @@
11
# swift-extras-uuid
22

3-
A reimplementation of UUID in Swift without the use of Foundation.
3+
A reimplementation of UUID in Swift without the use of Foundation or any other dependency.
4+
5+
[![Swift 5.1](https://img.shields.io/badge/Swift-5.1-blue.svg)](https://swift.org/download/)
6+
[![github-actions](https://github.com/fabianfett/swift-extras-uuid/workflows/CI/badge.svg)](https://github.com/fabianfett/swift-extras-uuid/actions)
7+
[![codecov](https://codecov.io/gh/fabianfett/swift-extras-uuid/branch/main/graph/badge.svg)](https://codecov.io/gh/fabianfett/swift-extras-uuid)
8+
![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)
9+
![tuxOS](https://img.shields.io/badge/os-tuxOS-green.svg?style=flat)
10+
11+
### Motivation
12+
13+
Foundation on non Darwin platforms (Linux, Windows) has often worse performance and/or missing features compared to its Darwin counterpart. That's why I like to limit the use of Foundation classes and structs to the absolute minimum when writing server side or cross platform Swift code. This package offers the same UUID functionality that Foundation provides, without actually using Foundation. The performance is slightly better on Linux compared to the Foundation implementation and comparable on macOS.
14+
15+
### How to use it?
16+
17+
Add dependency to your `Package.swift`.
18+
19+
```swift
20+
dependencies: [
21+
.package(url: "https://github.com/fabianfett/swift-extras-uuid.git", .upToNextMajor(from: "0.1.0")),
22+
],
23+
```
24+
25+
Add `ExtrasUUID` to the target you want to use it in.
26+
27+
```swift
28+
targets: [
29+
.target(name: "MyFancyTarget", dependencies: [
30+
.product(name: "ExtrasUUID", package: "swift-extras-uuid"),
31+
])
32+
]
33+
```
34+
35+
Import the library and use it. This package's UUID is prefixed with an X to avoid naming conflicts in cases where you import Foundation in the same file.
36+
37+
```swift
38+
import ExtrasUUID
39+
40+
let uuid = XUUID()
41+
```
42+
43+
### Interop with Foundation
44+
45+
You can easily convert between a Foundation UUID and an swift-extras XUUID.
46+
47+
From Foundation:
48+
49+
```swift
50+
let fduuid = UUID()
51+
let xuuid = XUUID(uuid: fduuid.uuid)
52+
```
53+
54+
To Foundation:
55+
```swift
56+
let xuuid = XUUID()
57+
let fduuid = UUID(uuid: xuuid.uuid)
58+
```
59+
60+
### Performance
61+
62+
To run simple performance tests, check out this repository and run:
63+
64+
```
65+
swift run -c release --enable-test-discovery
66+
```
67+
68+
The performance tests will
69+
70+
- create 1m uuids
71+
- parse 1m uuids
72+
- create 1m uuid strings
73+
- compare 10k uuids
74+
75+
#### Linux - Swift 5.3
76+
77+
| | Creating Random | Parsing | Stringify | Comparing |
78+
|:--|:--|:--|:--|:--|
79+
| Foundation | 3.94s | 1.01s | 0.8s | 0.16s |
80+
| ExtrasUUID | 2.06s | 0.34s | 0.16s | 0.13s |
81+
| Speedup | ~2x | ~3x | ~5x | ~1x |
82+

0 commit comments

Comments
 (0)