Skip to content

Instantly share code, notes, and snippets.

@M0rtyMerr
Last active April 22, 2024 07:48
Show Gist options
  • Select an option

  • Save M0rtyMerr/03a4e3fe9ef226227ea37fc9926a5095 to your computer and use it in GitHub Desktop.

Select an option

Save M0rtyMerr/03a4e3fe9ef226227ea37fc9926a5095 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) })
}
}
}
@M0rtyMerr

Copy link
Copy Markdown
Author
Time Memory
RxSwift 143 8230К
Combine 18 2060К

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment