Skip to content

Instantly share code, notes, and snippets.

View andersio's full-sized avatar

Anders Ha andersio

View GitHub Profile
protocol P {
func foo()
func bar()
}
extension P {
func foo() { print("foo() from P") }
func bar() { print("bar() from P") }
}
let info = mach_timebase_info_t.allocate(capacity: 1)
mach_timebase_info(info)
var avg: Double = 0
let lock: UnsafeMutableRawPointer!
if #available(macOS 10.12, iOS 10.0, *), true {
let lock1 = os_unfair_lock_t.allocate(capacity: 1)
lock1.initialize(to: os_unfair_lock())
lock = UnsafeMutableRawPointer(lock1)
import XCTest
import ReactiveSwift
import Result
private func _measure(times: UInt64 = 2_000_000, label: String = #function, _ action: (() -> UInt64) -> Void) {
var result: UInt64 = 0
var minResult: UInt64 = .max
for i in 0 ..< times {
var start: UInt64!
import XCTest
import ReactiveSwift
import Result
private func _measure(times: UInt64 = 2_000_000, label: String = #function, _ action: (() -> UInt64) -> Void) {
var result: UInt64 = 0
var minResult: UInt64 = .max
for i in 0 ..< times {
var start: UInt64!
import XCTest
private func _measure(times: UInt64 = 2_000_000, label: String = #function, _ action: (() -> UInt64) -> Void) {
var result: UInt64 = 0
var minResult: UInt64 = .max
for i in 0 ..< times {
var start: UInt64!
action {
start = mach_absolute_time()
import XCTest
import ReactiveSwift
import Result
private func _measure(times: UInt64 = 2_000_000, label: String = #function, _ action: (() -> UInt64) -> Void) {
var result: UInt64 = 0
var minResult: UInt64 = .max
for i in 0 ..< times {
var start: UInt64!
class ManuallyFinishingOperation: BlockOperation {
override var isFinished: Bool {
return _isFinished && super.isFinished
}
var _isFinished: Bool = false {
willSet { willChangeValue(forKey: "isFinished") }
didSet { didChangeValue(forKey: "isFinished") }
}
import XCTest
import ReactiveSwift
import Result
private func _measure(times: UInt64 = 2_000_000, label: String = #function, _ action: (() -> UInt64) -> Void) {
var result: UInt64 = 0
var minResult: UInt64 = .max
for i in 0 ..< times {
var start: UInt64!
import XCTest
import ReactiveSwift
import Result
class BagTests: XCTestCase {
func testCopying() {
var _bag = Bag<Int>()
_ = (0 ..< 32_768).map { _bag.insert($0) }
self.measure {
// `Entity` protocol.
protocol Entity: Codeable {
var identifier: UInt { get }
}
protocol EntityIdentifer: Codeable {
var identifier: UInt { get }
}
struct Identifier<E: Entity>: EntityIdentifer {