···11+# I'd love for this to work but it's not quite right right now. The table in the README is copied manually.
22+13import re
2435def to_ns(val, unit):
+27-27
README.md
···7788[CBOR](https://cbor.io/) is a flexible data format that emphasizes extremely small code size, small message size, and extendability. This library provides a Swift API for encoding and decoding Swift types using the CBOR serialization format.
991010-The motivation for this library over existing implementations is twofold: performance, and reliability. Existing community implementations do not make correct use of Swift features like `Optional` and memory safety. This library aims to be safe while still outperforming other implementations. To that end, this library has been extensively [fuzz tested](./Fuzzing.md) to ensure your application never crashes due to malicious input. At the same time, this library boasts up to a *74% faster* encoding and up to *89% faster* decoding than existing implementations. See [benchmarks](#benchmarks) for more details.
1010+The motivation for this library over existing implementations is twofold: performance, and reliability. Existing community implementations do not make correct use of Swift features like `Optional` and memory safety. This library aims to be safe while still outperforming other implementations. To that end, this library has been extensively [fuzz tested](./Fuzz.md) to ensure your application never crashes due to malicious input. At the same time, this library boasts up to a *74% faster* encoding and up to *89% faster* decoding than existing implementations. See [benchmarks](#benchmarks) for more details.
11111212## Usage
1313···78787979| Benchmark | SwiftCBOR (ns, p50) | CBOR (ns, p50) | % Improvement |
8080|-----------|----------------|-----------|------------|
8181-| Array | 23 | 7 | **69.57%** |
8282-| Complex Object | 700,000 | 74,000 | **89.43%** |
8383-| Date | 5,211 | 1,042 | **80.00%** |
8484-| Dictionary | 17 | 5 | **70.59%** |
8585-| Double | 5,251 | 1,000 | **80.96%** |
8686-| Float | 5,251 | 1,000 | **80.96%** |
8787-| Indeterminate String | 6,251 | 1,375 | **78.00%** |
8888-| Int | 5,211 | 1,124 | **78.43%** |
8989-| Int Small | 5,167 | 1,083 | **79.04%** |
9090-| Simple Object | 36 | 8 | **77.78%** |
9191-| String | 5,419 | 1,251 | **76.91%** |
9292-| String Small | 5,251 | 1,125 | **78.58%** |
8181+| Array | 23 | 7 | **70%** |
8282+| Complex Object | 703 μs | 75 μs | **89%** |
8383+| Date | 5,251 | 1,083 | **79%** |
8484+| Dictionary | 17 | 5 | **71%** |
8585+| Double | 5,295 | 1,001 | **81%** |
8686+| Float | 5,295 | 1,000 | **81%** |
8787+| Indeterminate String | 6,251 | 1,417 | **77%** |
8888+| Int | 5,211 | 1,125 | **78%** |
8989+| Int Small | 5,211 | 1,083 | **79%** |
9090+| Simple Object | 36 | 8 | **78%** |
9191+| String | 5,459 | 1,292 | **76%** |
9292+| String Small | 5,291 | 1,126 | **79%** |
93939494### Encoding (cpu time)
95959696-| Benchmark | SwiftCBOR (ns, p50) | CBOR (ns, p50) | % Improvement |
9696+| Benchmark | SwiftCBOR (ns, p50) | CBOR (ns, p50) | % Improvement |
9797|-----------|----------------|-----------|------------|
9898-| Array | 666,000 | 471,000 | **29.28%** |
9999-| Array Small | 7,003 | 2,875 | **58.95%** |
100100-| Bool | 3,167 | 1,124 | **64.51%** |
101101-| Complex Codable Object | 124,000 | 92,000 | **25.81%** |
102102-| Data | 5,295 | 1,208 | **77.19%** |
103103-| Data Small | 3,917 | 959 | **75.52%** |
104104-| Dictionary | 11 | 5 | **54.55%** |
105105-| Dictionary Small | 7,419 | 2,875 | **61.25%** |
106106-| Int | 3,959 | 1,291 | **67.39%** |
107107-| Int Small | 3,793 | 1,208 | **68.15%** |
108108-| Simple Codable Object | 18 | 9 | **50.00%** |
109109-| String | 5,543 | 1,250 | **77.45%** |
110110-| String Small | 4,001 | 1,125 | **71.88%** |
9898+| Array | 669 μs | 471 μs | **30%** |
9999+| Array Small | 7,043 | 2,917 | **59%** |
100100+| Bool | 3,169 | 1,125 | **64%** |
101101+| Complex Codable Object | 124 μs | 92 μs | **26%** |
102102+| Data | 5,335 | 1,250 | **77%** |
103103+| Data Small | 3,959 | 1000 | **75%** |
104104+| Dictionary | 11 | 5 | **55%** |
105105+| Dictionary Small | 7,459 | 2,959 | **60%** |
106106+| Int | 4,001 | 1,292 | **68%** |
107107+| Int Small | 3,833 | 1,208 | **68%** |
108108+| Simple Codable Object | 18 | 9 | **50%** |
109109+| String | 5,583 | 1,291 | **77%** |
110110+| String Small | 4,041 | 1,125 | **72%** |
111111112112## Contributing
113113