Last active
April 22, 2024 07:48
-
-
Save M0rtyMerr/03a4e3fe9ef226227ea37fc9926a5095 to your computer and use it in GitHub Desktop.
Combine vs RxSwift perfomance
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 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) }) | |
} | |
} | |
} |
Author
M0rtyMerr
commented
Jun 12, 2019
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