Java vs C/Objective-C performance question
Java vs C/Objective-C performance question
- Subject: Java vs C/Objective-C performance question
- From: Sheehan Olver <email@hidden>
- Date: Mon, 17 Mar 2003 01:34:57 -0600
I was curious about what the difference between performance of java
and Objective-C was, and I got some weird results in a couple tests I
did. See the bottom of the message for the code. For the first test,
which was really a comparison of java to C, java took 11 seconds while
C took 25 seconds, which makes no sense to me whatsoever, as I don't
understand how java could outperform C. For the second test, which is
more relevant to Objective-C, I got java taking 2 seconds to
Objective-Cs 14 seconds. Again, this just doesn't make much sense. Any
ideas on why I'm getting these results? I ran the tests multiple times,
and the times were similar.
I'm running 10.2.4 on a PowerBook G4 550Mhz, with java 1.4.1
installed. Both tests were done from Project Builder, but as command
line tools (i.e. within the main function).
Results:
Java:
Before 1: Sun Mar 16 16:13:24 CST 2003
After 1: Sun Mar 16 16:13:35 CST 2003
Before 2: Sun Mar 16 16:13:35 CST 2003
After 2: Sun Mar 16 16:13:37 CST 2003
Objective-C:
2003-03-16 16:10:43.426 CocoaTest[4012] Before 1: 2003-03-16 16:10:43
-0600
2003-03-16 16:11:08.745 CocoaTest[4012] After 1: 2003-03-16 16:11:08
-0600
2003-03-16 16:11:53.406 CocoaTest[4034] Before 2: 2003-03-16 16:11:53
-0600
2003-03-16 16:12:17.392 CocoaTest[4034] After 2: 2003-03-16 16:12:17
-0600
Code:
Java Code:
int i, j, k;
long count = 0;
System.out.println("Before 1: " + new Date());
for(i = 0; i < 10; i++) {
for(j = 0; j < 10000; j++) {
for(k = 0; k < 10000; k++) {
count++;
}
}
}
System.out.println("After 1: " + new Date());
System.out.println("Before 2: " + new Date());
for(j = 0; j < 1000; j++) {
for(i = 0; i < 10000; i++) {
new Object();
}
}
System.out.println("After 2: " + new Date());
Objective-C code:
int i, j, k;
long count = 0;
NSLog(@"Before 1: %@", [[NSDate date] description]);
for(i = 0; i < 10; i++) {
for(j = 0; j < 10000; j++) {
for(k = 0; k < 10000; k++) {
count++;
}
}
}
NSLog(@"After 1: %@", [[NSDate date] description]);
NSLog(@"Before 2: %@", [[NSDate date] description]);
for(j = 0; j < 1000; j++) {
for(i = 0; i < 10000; i++) {
[[[NSObject alloc] init] release];
}
}
NSLog(@"After 2: %@", [[NSDate date] description]);
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.