Skip to content

Latest commit

 

History

History
128 lines (85 loc) · 4.01 KB

Readme.md

File metadata and controls

128 lines (85 loc) · 4.01 KB

Combine vs. RxSwift Performance Benchmark Test Suite 📊

This project contains a benchmarking test suite for comparing the performance of the most commonly used components and operators in RxSwift and Combine. For a detailed comparison of RxSwift with Combine have a look at our blog post.

The RxSwift performance benchmark tests are the original ones used in the RxSwift project. We removed the two tests from RxCocoa testing Drivers, since there is no equivalent in Combine. The Combine tests are 1:1 translated tests from the Rx test-suite and should, therefore, be easily comparable.

Important update: As mentioned correctly the old numbers were created with XCTests running in DEBUG mode. The differences seem not so critical in Release builds. We have updated all the numbers and graphs to use release builds.

As a summary Combine was faster in every test and on average 41% more performant than RxSwift. These statistics show every test-method and its results. Lower is better.

Test Results Summary

Test RxSwift (ms) Combine (ms) Factor
PublishSubjectPumping 227 135 168%
PublishSubjectPumpingTwoSubscriptions 400 246 163%
PublishSubjectCreating 295 250 118%
MapFilterPumping 123 132 93%
MapFilterCreating 168 114 147%
FlatMapsPumping 646 367 176%
FlatMapsCreating 214 121 177%
FlatMapLatestPumping 810 696 116%
FlatMapLatestCreating 263 180 146%
CombineLatestPumping 298 282 106%
CombineLatestCreating 644 467 138%

Testing Details

Machine: MacBook Pro 2018, 2,7 GHz Intel Core i7, 16 GB IDE: Xcode 11.0 beta 5 (11M382q) Testing Device: iPhone XR Simulator

Performance Test Example: PublishSubject Pumping

For every test we replace the RxSwift component with the corresponding Combine component. In this case PublishSubject with PassthroughSubject.

RxSwift

func testPublishSubjectPumping() {
    measure {
        var sum = 0
        let subject = PublishSubject<Int>()

        let subscription = subject
            .subscribe(onNext: { x in
                sum += x
            })

        for _ in 0 ..< iterations * 100 {
            subject.on(.next(1))
        }

        subscription.dispose()

        XCTAssertEqual(sum, iterations * 100)
    }
}

Combine

func testPublishSubjectPumping() {
    measure {
        var sum = 0
        let subject = PassthroughSubject<Int, Never>()

        let subscription = subject
            .sink(receiveValue: { x in
                sum += x
            })

        for _ in 0 ..< iterations * 100 {
            subject.send(1)
        }
        
        subscription.cancel()
        
        XCTAssertEqual(sum, iterations * 100)
    }
}

Detailed Performance Test Results: RxSwift vs. Combine

PublishSubjectPumping

PublishSubjectPumpingTwoSubscriptions

PublishSubjectCreating

MapFilterPumping

MapFilterCreating

FlatMapsPumping

FlatMapsCreating

FlatMapLatestPumping

FlatMapLatestCreating

CombineLatestPumping

CombineLatestCreating