Skip to content

Instantly share code, notes, and snippets.

@sakrist
Last active December 17, 2015 21:59
Show Gist options
  • Save sakrist/5678224 to your computer and use it in GitHub Desktop.
Save sakrist/5678224 to your computer and use it in GitHub Desktop.
/*/../bin/ls > /dev/null
COMPILED=${0%.*}
clang $0 -o $COMPILED -framework Foundation;
$COMPILED; rm $COMPILED; exit;
*/
#import <Foundation/Foundation.h>
@class CNSObject;
@interface CNSObject : NSObject
@property (nonatomic, retain) NSObject *obj;
@property (nonatomic, retain) CNSObject *obj_obj;
@property (nonatomic) bool b;
@property (nonatomic) BOOL bb;
@end
@implementation CNSObject
@end
int main(int argc, char *argv[])
{
@autoreleasepool
{
CNSObject *obj = [[CNSObject alloc] init];
obj.obj_obj = [[CNSObject alloc] init];
obj.obj_obj.obj_obj = [[CNSObject alloc] init];
void (^simpleBlock)(void);
simpleBlock = ^{
};
double t;
int it_times = INT_MAX;
NSLog(@"Testing \"for\" with %d iterations and different if's", it_times);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (obj) {
}
}
NSLog(@"object is not nil %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (obj.b) {
}
}
NSLog(@"object check bool %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (obj.bb) {
}
}
NSLog(@"object check BOOL %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (obj.obj) {
}
}
NSLog(@"object has object %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (obj.obj_obj) {
}
}
NSLog(@"object has object which is not nil %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (obj.obj_obj.obj_obj) {
}
}
NSLog(@"object has 3 level of objects %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if ([obj isKindOfClass:[CNSObject class]]) {
}
}
NSLog(@"object isKindOfClass %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
simpleBlock();
}
NSLog(@"perform block %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < it_times; i++) {
if (simpleBlock) {
simpleBlock();
}
}
NSLog(@"block is available and perform then %f sec", CFAbsoluteTimeGetCurrent()-t);
t = CFAbsoluteTimeGetCurrent();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment