Forked from M0rtyMerr/combine_vs_RxSwift_perfomance.swift
Created
July 3, 2019 09:36
-
-
Save victor-pavlychko/3bc48ea1e6c43fca3a96656c962e07f5 to your computer and use it in GitHub Desktop.
Combine vs RxSwift perfomance
This file contains hidden or 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) }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment