Skip to content

Instantly share code, notes, and snippets.

@andersio
Created April 17, 2017 07:54
Show Gist options
  • Select an option

  • Save andersio/1f3a118c88dc17e602d0b0a2abd191a9 to your computer and use it in GitHub Desktop.

Select an option

Save andersio/1f3a118c88dc17e602d0b0a2abd191a9 to your computer and use it in GitHub Desktop.
import XCTest
import ReactiveSwift
import Result
class Test: XCTestCase {
func testPerformanceExample() {
let (signal, observer) = Signal<Int, NoError>.pipe()
let transformed = signal
.map { $0 + Int(arc4random() % 5 as UInt32) }
.map { $0 + Int(arc4random() % 4 as UInt32) }
.map { $0 + Int(arc4random() % 3 as UInt32) }
.map { $0 + Int(arc4random() % 2 as UInt32) }
var values: [Int] = []
transformed.observeValues { value in
if !values.contains(value) {
values.append(value)
}
}
self.measure {
for _ in 1 ... 10000 {
observer.send(value: Int(arc4random() % 5) - 4)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment