Skip to content

Instantly share code, notes, and snippets.

@andersio
Created November 13, 2016 15:26
Show Gist options
  • Select an option

  • Save andersio/530cfa5a314d2b13b28ec935fc352fac to your computer and use it in GitHub Desktop.

Select an option

Save andersio/530cfa5a314d2b13b28ec935fc352fac to your computer and use it in GitHub Desktop.
//
// 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