Created
November 13, 2016 15:26
-
-
Save andersio/530cfa5a314d2b13b28ec935fc352fac to your computer and use it in GitHub Desktop.
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
| // | |
| // NSObjectRACSelectorSignalPerformanceTests.m | |
| // ReactiveObjC | |
| // | |
| // Created by Anders on 13/11/2016. | |
| // Copyright © 2016 GitHub. All rights reserved. | |
| // | |
| @import Nimble; | |
| #import <XCTest/XCTest.h> | |
| #import "RACTestObject.h" | |
| #import "NSObject+RACSelectorSignal.h" | |
| #import "RACSignal.h" | |
| #import "NSObject+RACPropertySubscribing.h" | |
| @interface NSObjectRACSelectorSignalPerformanceTests : XCTestCase | |
| @end | |
| @implementation NSObjectRACSelectorSignalPerformanceTests | |
| - (void)testPerformanceExample { | |
| RACTestObject* object = [[RACTestObject alloc] init]; | |
| [self measureBlock:^{ | |
| __block unsigned int racCount = 0, kvoCount = 0; | |
| [[object rac_signalForSelector:@selector(setObjectValue:)] subscribeNext:^(id value) { | |
| racCount += 1; | |
| }]; | |
| [RACObserve(object, objectValue) subscribeNext:^(id value) { | |
| kvoCount += 1; | |
| }]; | |
| unsigned int iterations = 100000; | |
| for (unsigned int i = 0; i < iterations; i++) { | |
| [object setObjectValue:@(i)]; | |
| } | |
| expect(object.objectValue).to(equal(@(iterations - 1))); | |
| expect(@(racCount)).to(equal(@(iterations))); | |
| expect(@(kvoCount)).to(equal(@(iterations + 1))); | |
| }]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment