| 
6 | 6 |   | 
7 | 7 |   | 
8 | 8 | 
 
  | 
9 |  | -The goal of this project is to provide an easy to use base64 encode and decode algorithm   | 
10 |  | -without the use of the Foundation framework.   | 
 | 9 | +The goal of this project is to provide an easy to use [RFC4648](https://tools.ietf.org/html/rfc4648)   | 
 | 10 | +complient base64 encode and decode implentation in pure Swift. Further this implementation  | 
 | 11 | +tries to be faster than the [Foundation Base64](https://developer.apple.com/documentation/foundation/nsdata)   | 
 | 12 | +implementation.   | 
 | 13 | + | 
 | 14 | +Right now the implementation is dead simple. No fancy precomputed lookup tables, no fancy   | 
 | 15 | +SIMD instructions.   | 
11 | 16 | 
 
  | 
12 | 17 | Everything began with [an issue](https://github.com/apple/swift-nio/issues/1265) on [`swift-nio`](https://github.com/apple/swift-nio).  | 
13 | 18 | 
 
  | 
 | 19 | +## Status  | 
 | 20 | + | 
 | 21 | +- [x] support for base64 and base64url   | 
 | 22 | +- [x] faster than Foundation  | 
 | 23 | +- [ ] decoding can ignore line breaks  | 
 | 24 | +- [ ] encoding can insert line breaks  | 
 | 25 | +- [ ] 100% test coverage  | 
 | 26 | + | 
 | 27 | +## Performance  | 
 | 28 | + | 
 | 29 | +Super [simple performance test](https://github.com/fabianfett/swift-base64/blob/master/Sources/Base64PerformanceTest/main.swift)   | 
 | 30 | +to ensure speediness of this implementation. Encoding and decoding 1m times the base64 string:  | 
 | 31 | + | 
 | 32 | +```  | 
 | 33 | +AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==  | 
 | 34 | +```  | 
 | 35 | + | 
 | 36 | +#### macOS  | 
 | 37 | + | 
 | 38 | +MacBook Pro (15-inch, late 2016 - the first one with the butterfly keyboard).   | 
 | 39 | +Quad Core 2,7 GHz Intel Core i7  | 
 | 40 | + | 
 | 41 | +|  | Encoding | Decoding |  | 
 | 42 | +|:--|:--|:--|  | 
 | 43 | +| Foundation   | 2.21s | 2.28s |  | 
 | 44 | +| swift-base64 | 1.01s | 1.06s |  | 
 | 45 | +| Speedup | 2.18x | 2.14x |  | 
 | 46 | + | 
 | 47 | +#### linux  | 
 | 48 | + | 
 | 49 | +Whatevar runs GitHub Actions 😉  | 
 | 50 | + | 
 | 51 | +|  | Encoding | Decoding |  | 
 | 52 | +|:--|:--|:--|  | 
 | 53 | +| Foundation   | 33.64s | 3.49s |  | 
 | 54 | +| swift-base64 | 1.07s | 1.27s |  | 
 | 55 | +| Speedup | 31.18x | 2.74x |  | 
 | 56 | + | 
 | 57 | +I have no idea why Foundation base64 encoding is so slow on linux. 🤷♂️  | 
 | 58 | + | 
 | 59 | +## Literature for a faster algorithm  | 
 | 60 | + | 
 | 61 | +I would really like to speedup this repository further to be way faster than it is today.  | 
 | 62 | +Some food for thought of how this could be approached can be found here:  | 
 | 63 | + | 
 | 64 | +- [Chromium precomputed lookup tables](https://github.com/lemire/fastbase64/blob/master/src/chromiumbase64.c)  | 
 | 65 | +- [Wojciech Muła, Daniel Lemire: Faster Base64 Encoding and Decoding using AVX2 Instructions](https://arxiv.org/pdf/1704.00605.pdf).  | 
 | 66 | +- [Daniel Lemire's blog - Ridiculously fast base64 encoding and decoding](https://lemire.me/blog/2018/01/17/ridiculously-fast-base64-encoding-and-decoding/)  | 
 | 67 | +- [Swift SIMD support](https://github.com/apple/swift-evolution/blob/master/proposals/0229-simd.md)  | 
 | 68 | + | 
 | 69 | +## Alternatives  | 
14 | 70 | 
 
  | 
15 |  | -### Maybe one day, we can make this really swift.  | 
 | 71 | +As of today (2019-12-10) the author is only aware of two alternatives that both offer   | 
 | 72 | +only encoding. Only one of those is a real library.  | 
16 | 73 | 
 
  | 
17 |  | -Some literature:  | 
 | 74 | +- [SwiftyBase64](https://github.com/drichardson/SwiftyBase64)  | 
 | 75 | +- [NIOWebSocket - Base64](https://github.com/apple/swift-nio/blob/master/Sources/NIOWebSocket/Base64.swift)  | 
18 | 76 | 
 
  | 
19 |  | -- [RFC4648](https://tools.ietf.org/html/rfc4648)   | 
20 |  | -- [Ridiculously fast base64 encoding and decoding - Daniel Lemire's blog](https://lemire.me/blog/2018/01/17/ridiculously-fast-base64-encoding-and-decoding/)  | 
 | 
0 commit comments