Code Monkey home page Code Monkey logo

combinerxswiftperformance's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.