Skip to content

Commit 6dc88d2

Browse files
committed
Added Objective-C
1 parent 3cabaf6 commit 6dc88d2

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

runTest.sh

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ gcc -o /tmp/test test.c
1414
gcc test.cpp -o /tmp/test
1515
/tmp/test
1616

17+
# Objective-C
18+
gcc test.m -o /tmp/testObjective-C -framework Foundation -framework QuartzCore
19+
/tmp/testObjective-C
20+
1721
# Java
1822
javac -d /tmp/ Test.java
1923
java -cp "/tmp/" Test

test.m

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// test.m
3+
// Test
4+
//
5+
// Created by Prang, Andreas on 09.12.15.
6+
// Copyright © 2015 iSolute-Berlin. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <QuartzCore/QuartzCore.h>
11+
12+
#if __has_feature(objc_arc)
13+
#define DLog(format, ...) CFShow((__bridge CFStringRef)[NSString stringWithFormat:format, ## __VA_ARGS__]);
14+
#else
15+
#define DLog(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
16+
#endif
17+
18+
@interface Test:NSObject
19+
- (long)forEachLoopMaxInteger:(long)max;
20+
@end
21+
22+
@implementation Test
23+
- (long)forEachLoopMaxInteger:(long)max {
24+
long sum = 0;
25+
for (long n = max; n > 0; n--) {
26+
double foo = n / 17;
27+
sum = sum + n ;
28+
}
29+
return max;
30+
}
31+
@end
32+
33+
int main(int argc, const char * argv[]) {
34+
@autoreleasepool {
35+
36+
Test *test = [[Test alloc]init];
37+
CFTimeInterval startTime = CACurrentMediaTime();
38+
[test forEachLoopMaxInteger:100000000];
39+
CFTimeInterval elapsedTime = CACurrentMediaTime() - startTime;
40+
41+
DLog(@"Objective-C: %.0f", elapsedTime * 1000);
42+
}
43+
return 0;
44+
}

test.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func forEachLoopMaxInteger(max: Int64) -> Int64 {
88
var sum : Int64 = 0
99
for (var n = max; n > 0; n--) {
1010
let _ = n / 17
11-
sum = sum + n
11+
sum = sum + n
1212
}
1313
return max;
1414
}

0 commit comments

Comments
 (0)