Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victor-pavlychko/3bc48ea1e6c43fca3a96656c962e07f5 to your computer and use it in GitHub Desktop.
Save victor-pavlychko/3bc48ea1e6c43fca3a96656c962e07f5 to your computer and use it in GitHub Desktop.
Combine vs RxSwift perfomance
import XCTest
import Combine
import RxSwift
final class PlaygroundTests: XCTestCase {
private let input = stride(from: 0, to: 10_000_000, by: 1)
override class var defaultPerformanceMetrics: [XCTPerformanceMetric] {
return [
XCTPerformanceMetric("com.apple.XCTPerformanceMetric_TransientHeapAllocationsKilobytes"),
.wallClockTime
]
}
func testCombine() {
self.measure {
_ = Publishers.Sequence(sequence: input)
.map { $0 * 2 }
.filter { $0.isMultiple(of: 2) }
.flatMap { Publishers.Just($0) }
.count()
.sink(receiveValue: {
print($0)
})
}
}
func testRxSwift() {
self.measure {
_ = Observable.from(input)
.map { $0 * 2 }
.filter { $0.isMultiple(of: 2) }
.flatMap { Observable.just($0) }
.toArray()
.map { $0.count }
.subscribe(onSuccess: { print($0) })
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment