Last active
April 29, 2017 06:38
-
-
Save andersio/14e636c03b6915254fd2b9a948a83a20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
import ReactiveSwift | |
import Result | |
class BagTests: XCTestCase { | |
func testCopying() { | |
var _bag = Bag<Int>() | |
_ = (0 ..< 32_768).map { _bag.insert($0) } | |
self.measure { | |
var bag = _bag | |
bag.insert(.max) | |
} | |
} | |
func testIterationOfOne() { | |
var bag = Bag<Int>() | |
_ = bag.insert(0) | |
self.measure { | |
for _ in 0 ..< 100_000 { | |
for i in bag { | |
_ = i | |
} | |
} | |
} | |
} | |
func testIteration() { | |
var bag = Bag<Int>() | |
_ = (0 ..< 128).map { bag.insert($0) } | |
self.measure { | |
for _ in 0 ..< 100_000 { | |
for i in bag { | |
_ = i | |
} | |
} | |
} | |
} | |
func testInsertion() { | |
self.measure { | |
var bag = Bag<Int>() | |
for i in 0 ..< 100_000 { | |
bag.insert(i) | |
} | |
} | |
} | |
func testFastPathRemoval() { | |
var _bag = Bag<Int>() | |
let tokens = (0 ..< 32_768).map { _bag.insert($0) } | |
self.measure { | |
var bag = _bag | |
for token in tokens.reversed() { | |
bag.remove(using: token) | |
} | |
} | |
} | |
func testAverageRemoval() { | |
var _bag = Bag<Int>() | |
let tokens = (0 ..< 32_768).map { _bag.insert($0) } | |
self.measure { | |
var bag = _bag | |
for token in tokens { | |
bag.remove(using: token) | |
} | |
} | |
} | |
func testSignalDelivery() { | |
let (signal, observer) = Signal<Int, NoError>.pipe() | |
_ = (0 ..< 16).map { _ in signal.observe { _ in } } | |
self.measure { | |
for i in 0 ..< 100_000 { | |
observer.send(value: i) | |
} | |
} | |
} | |
func testDisposableDetachment() { | |
self.measureMetrics(XCTestCase.defaultPerformanceMetrics(), automaticallyStartMeasuring: false) { | |
let (signal, observer) = Signal<Int, NoError>.pipe() | |
// Worst case: Removing from the earliest ones. | |
let disposables = (0 ..< 128).map { _ in signal.observe { _ in } } | |
self.startMeasuring() | |
for disposable in disposables { | |
disposable?.dispose() | |
} | |
self.stopMeasuring() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment