I hereby claim:
- I am airspeedswift on github.
- I am airspeedvelocity (https://keybase.io/airspeedvelocity) on keybase.
- I have a public key whose fingerprint is BAC5 2735 2DC2 8822 2A8B EFC1 ECB5 1983 1587 0DBE
To claim this, I am signing this object:
| // code originally adapted from https://github.com/DuncanMC/SwiftPerformanceBenchmark | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <CoreFoundation/CFDate.h> | |
| void updateTotal(int newTotal, CFAbsoluteTime startTime) { | |
| CFAbsoluteTime now = CFAbsoluteTimeGetCurrent(); | |
| CFAbsoluteTime totalTime = now - startTime; |
| import Foundation | |
| @objc class MyClass: NSObject { | |
| var someProperty: Int | |
| init(_ x: Int) { someProperty = x } | |
| } | |
| let classes: [AnyObject] = (0..<10_000).map { _ in MyClass(Int(arc4random())) } | |
| func timeRun<T>(name: String, f: ()->T) -> String { | |
| let start = CFAbsoluteTimeGetCurrent() |
| import Darwin | |
| import CoreFoundation.CFDate | |
| protocol NumberGeneratorType { | |
| mutating func generateNumber() -> Int | |
| } | |
| struct RandomGenerator: NumberGeneratorType { | |
| func generateNumber() -> Int { | |
| return Int(arc4random_uniform(10)) |
| /// Brian Kernighan's article in Beautiful Code talks about the minimalist regex matcher written by | |
| /// Rob Pike for their Practice of Programming book as "one of the best examples of recursion that I | |
| /// have ever seen, and it shows the power of C pointers". | |
| /// | |
| /// Swift strings don't use pointers, and the original code relied heavily on the last character of a | |
| /// C string being `\0`, but you can reproduce many of the nice aspects of the original C code using a | |
| /// combination of slicing and `dropFirst`, the `first` function that returns an optional you can then | |
| /// compare to a non-optional character, and the Swift 1.2 `if...let...where` | |
| /// | |
| /// In theory no string copying should be happening since the slices are just a subrange view on the |
| import Foundation | |
| protocol P { | |
| func f(i: Int) | |
| } | |
| func g<T: P>(t: T) { | |
| let f = { t.dynamicType.f($0) } | |
| } |
| struct NibbleCollection: MutableCollectionType { | |
| var val: UInt64 | |
| init(_ val: UInt64) { self.val = val } | |
| typealias Index = UInt64 | |
| let startIndex: UInt64 = 0 | |
| let endIndex: UInt64 = 16 | |
| subscript(idx: UInt64) -> UInt64 { | |
| get { |
| // ideally we would define this inside the tree struct | |
| private class _Node<T: Comparable> { | |
| var _value: T | |
| var _left: _Node<T>? = nil | |
| var _right: _Node<T>? = nil | |
| init(value: T) { _value = value } | |
| } |
I hereby claim:
To claim this, I am signing this object:
| // Note this is a class not a struct, so it does NOT have value semantics | |
| public class UnsafeCollection<T> { | |
| private var _len: Int = 0 | |
| private var _buflen: Int = 0 | |
| private var _buf: UnsafeMutablePointer<T> = nil | |
| public func removeAll(keepCapacity: Bool = false) { | |
| _buf.destroy(_len) | |
| _len = 0 | |
| if !keepCapacity { |
| let count = 12 | |
| // Simple class that prints when it is created and destroyed | |
| class Whiner { | |
| let _i: Int | |
| init(_ i: Int) { _i = i; println("Init: \(_i)") } | |
| deinit { println("Deinit: \(_i)") } | |
| } |