Last active
May 6, 2016 04:32
-
-
Save KanybekMomukeyev/0754bf5de98088c619718d9cb3d5fb22 to your computer and use it in GitHub Desktop.
Compare the speed of SSignalKit and ReactiveCocoa
This file contains 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
@implementation GRTestRacAndSSignalKit | |
- (instancetype)init | |
{ | |
self = [super init]; | |
if (self != nil) | |
{ | |
} | |
return self; | |
} | |
+ (instancetype)sharedInstance | |
{ | |
static dispatch_once_t once; | |
static GRTestRacAndSSignalKit *sharedInstance; | |
dispatch_once(&once, ^{ | |
sharedInstance = [[GRTestRacAndSSignalKit alloc] init]; | |
}); | |
return sharedInstance; | |
} | |
- (void)runTest | |
{ | |
[self testRac1]; | |
[self testSsignalKit1]; | |
[self testRac2]; | |
[self testSsignalKit2]; | |
} | |
- (void)testRac1 | |
{ | |
RACSignal *multipartRequest100 = [RACSignal createSignal:^RACDisposable * (id<RACSubscriber> subscriber) { | |
[subscriber sendNext:@(1000 * 1000)]; | |
[subscriber sendCompleted]; | |
return [RACDisposable disposableWithBlock:^{}]; | |
}]; | |
for (NSUInteger index = 0; index < 300; index ++) | |
{ | |
multipartRequest100 = [multipartRequest100 flattenMap:^RACStream *(NSNumber *numberValue) { | |
return [RACSignal createSignal:^RACDisposable * (id<RACSubscriber> subscriber) { | |
[subscriber sendNext:@(numberValue.integerValue/1000 * index)]; | |
[subscriber sendCompleted]; | |
return [RACDisposable disposableWithBlock:^{}]; | |
}]; | |
}]; | |
} | |
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); | |
[multipartRequest100 subscribeNext:^(NSNumber *resultNumber) { | |
NSLog(@"resultNumber in RACSINGAL == %@",resultNumber); | |
} error:^(NSError *error) { | |
} completed:^{ | |
CFAbsoluteTime executionTime = (CFAbsoluteTimeGetCurrent() - startTime); | |
if (executionTime > 0.0f) { | |
NSLog(@"***** RACSignal flattenMap: from took %f s", executionTime); | |
} | |
}]; | |
} | |
- (void)testSsignalKit1 | |
{ | |
SSignal *multipartRequest100 = [[SSignal alloc] initWithGenerator:^id<SDisposable> (SSubscriber *subscriber) | |
{ | |
[subscriber putNext:@(1000 * 1000)]; | |
[subscriber putCompletion]; | |
return [[SBlockDisposable alloc] initWithBlock:^{}]; | |
}]; | |
for (NSUInteger index = 0; index < 300; index ++) | |
{ | |
multipartRequest100 = [multipartRequest100 mapToSignal:^SSignal *(NSNumber *numberValue) { | |
return [[SSignal alloc] initWithGenerator:^id<SDisposable> (SSubscriber *subscriber) | |
{ | |
[subscriber putNext:@(numberValue.integerValue/1000 * index)]; | |
[subscriber putCompletion]; | |
return [[SBlockDisposable alloc] initWithBlock:^{}]; | |
}]; | |
}]; | |
} | |
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); | |
[multipartRequest100 startWithNext:^(NSNumber *resultNumber) { | |
NSLog(@"resultNumber in SSIGNAL == %@",resultNumber); | |
} error:^(id error) { | |
} completed:^{ | |
CFAbsoluteTime executionTime = (CFAbsoluteTimeGetCurrent() - startTime); | |
if (executionTime > 0.0f) { | |
NSLog(@"***** SSignal mapToSignal: from took %f s", executionTime); | |
} | |
}]; | |
} | |
- (void)testRac2 | |
{ | |
RACSignal *multipartRequest = [RACSignal createSignal:^RACDisposable * (id<RACSubscriber> subscriber) { | |
for (NSUInteger index = 0; index < 100000; index ++) | |
{ | |
[subscriber sendNext:@(index * 1000)]; | |
} | |
[subscriber sendCompleted]; | |
return [RACDisposable disposableWithBlock:^{}]; | |
}]; | |
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); | |
[multipartRequest subscribeNext:^(NSArray *resultItems) { | |
} error:^(NSError *error) { | |
} completed:^{ | |
CFAbsoluteTime executionTime = (CFAbsoluteTimeGetCurrent() - startTime); | |
NSLog(@"***** RACSignal from took %f s", executionTime); | |
}]; | |
} | |
- (void)testSsignalKit2 | |
{ | |
SSignal *multipartRequest = [[SSignal alloc] initWithGenerator:^id<SDisposable> (SSubscriber *subscriber) | |
{ | |
for (NSUInteger index = 0; index < 100000; index ++) | |
{ | |
[subscriber putNext:@(index * 1000)]; | |
} | |
[subscriber putCompletion]; | |
return [[SBlockDisposable alloc] initWithBlock:^{}]; | |
}]; | |
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); | |
[multipartRequest startWithNext:^(id next) { | |
} error:^(id error) { | |
} completed:^{ | |
CFAbsoluteTime executionTime = (CFAbsoluteTimeGetCurrent() - startTime); | |
NSLog(@"***** SSignal from took %f s", executionTime); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comments are wealcome!!!!