Skip to content

Instantly share code, notes, and snippets.

@RuiAAPeres RuiAAPeres/Reactive_tests.swift Secret
Last active Apr 27, 2016

Embed
What would you like to do?
//
// ReactTestTests.swift
// ReactTestTests
//
// Created by Rui Peres on 21/11/2015.
// Copyright © 2015 Test. All rights reserved.
//
import XCTest
import ReactiveCocoa
import Bond
import Interstellar
import RxSwift
class ReactTestTests: XCTestCase {
/// 0.143s (5% stdev)
func test_measure_ReactiveCocoa_1() {
measureBlock {
var counter : Int = 0
let (signal, observer) = ReactiveCocoa.Signal<Int, NoError>.pipe()
signal.observeNext { counter += $0 }
for i in 1..<100000 {
observer.sendNext(i)
}
}
}
/// 0.211s (3% stdev)
func test_measure_Bond_1() {
measureBlock {
var counter : Int = 0
let observable = Observable(0)
observable.observe { counter += $0 }
for i in 1..<100000 {
observable.next(i)
}
}
}
// 0.131s (3% stdev)
func test_measure_Interstellar_1() {
measureBlock {
var counter : Int = 0
let signal = Interstellar.Signal<Int>()
signal.next { counter += $0 }
for i in 1..<100000 {
signal.update(i)
}
}
}
// 0.049s (5% stdev)
func test_measure_RXSwift_1() {
measureBlock {
var counter : Int = 0
let observable = Variable(0)
let _ = observable.subscribeNext { counter += $0 }
for i in 1..<100000 {
observable.value = i
}
}
}
////////////////////////////////////////////
// 1.279s (2% stdev)
func test_measure_ReactiveCocoa_2() {
measureBlock {
var counter : Int = 0
let (signal, observer) = ReactiveCocoa.Signal<Int, NoError>.pipe()
for _ in 1..<30 {
signal.observeNext { counter += $0 }
}
for i in 1..<100000 {
observer.sendNext(i)
}
}
}
// 4.298s (3% stdev)
func test_measure_Bond_2() {
measureBlock {
var counter : Int = 0
let observable = Observable(0)
for _ in 1..<30 {
observable.observe { counter += $0 }
}
for i in 1..<100000 {
observable.next(i)
}
}
}
// 1.812s (15% stdev)
func test_measure_Interstellar_2() {
measureBlock {
var counter : Int = 0
let signal = Interstellar.Signal<Int>()
for _ in 1..<30 {
signal.next { counter += $0 }
}
for i in 1..<100000 {
signal.update(i)
}
}
}
// 1.228s (11% stdev)
func test_measure_RXSwift_2() {
measureBlock {
var counter : Int = 0
let observable = Variable(0)
for _ in 1..<30 {
let _ = observable.subscribeNext { counter += $0 }
}
for i in 1..<100000 {
observable.value = i
}
}
}
////////////////////////////////////////////
// 7.045s (1% stdev)
func test_measure_ReactiveCocoa_3() {
measureBlock {
let (signal, observer) = ReactiveCocoa.Signal<Int, NoError>.pipe()
for _ in 1..<30 {
signal.filter{ $0%2 == 0}.map(String.init).observeNext {_ in }
}
for i in 1..<100000 {
observer.sendNext(i)
}
}
}
// 11.283s (2% stdev)
func test_measure_Bond_3() {
measureBlock {
let observable = Observable(0)
for _ in 1..<30 {
observable.filter{ $0%2 == 0}.map(String.init).observe { _ in }
}
for i in 1..<100000 {
observable.next(i)
}
}
}
// 6.530s (1% stdev)
func test_measure_Interstellar_3() {
measureBlock {
let signal = Interstellar.Signal<Int>()
for _ in 1..<30 {
signal.filter{ $0%2 == 0}.map(String.init).next {_ in }
}
for i in 1..<100000 {
signal.update(i)
}
}
}
// 2.198s (3% stdev)
func test_measure_RXSwift_3() {
measureBlock {
let observable = Variable(0)
for _ in 1..<30 {
let _ = observable.filter{ $0%2 == 0}.map(String.init).subscribeNext {_ in }
}
for i in 1..<100000 {
observable.value = i
}
}
}
}
@fpillet

This comment has been minimized.

Copy link

commented Nov 21, 2015

Great, I had been thinking about doing something similar. Very good start for a reactive frameworks cross benchmark!

@kkodev

This comment has been minimized.

Copy link

commented Nov 21, 2015

Dude, get your newlines and spacing sorted out. It's a pain to read

@RuiAAPeres

This comment has been minimized.

Copy link
Owner Author

commented Nov 21, 2015

@kkodev sorry for making your life more difficult.

@scotteg

This comment has been minimized.

Copy link

commented Apr 19, 2016

Thanks @RuiAAPeres! I created a project with these tests: https://github.com/scotteg/ReactiveTesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.