Native Cocoa vs Java performance question
Native Cocoa vs Java performance question
- Subject: Native Cocoa vs Java performance question
- From: Adrian Milliner <email@hidden>
- Date: Sun, 6 Apr 2003 02:21:57 +0100
Hi,
I'm new to Cocoa and Objective-C, wanting to get better performance
compared to Java.
I did a quick test where I create an NSMutableDictionary and add 50000
objects. I created a similar test in Java using a HashSet.
The Cocoa test took 0.63 seconds
The Java (1.4.1) test took 0.288 seconds
The Java test with -Xms8mb flag took 0.16 seconds
Why is Cocoa (native code) so much slower than Java? Or am I doing
something really bad Cocoa-wise?
So much of what I need to do involves creating and maintaining large
hash tables, so on the face of it, I may be better off sticking with
Java... I hope not, because I do like Objective-C and Cocoa.
Adrian Milliner
The pertinent part of the Cocoa test is here:
-------------------------------------------------------------------
// pre create keys to avoid contaminating the hash test
for (i=0; i<50000; i++)
keys[i] = [NSString stringWithFormat:@"k%d",i*777];
start = [NSDate date];
dict = [[NSMutableDictionary alloc] initWithCapacity: 50000];
for (i=0; i<50000; i++) {
[dict setObject: @"hello" forKey: keys[i] ];
}
ti = [start timeIntervalSinceNow];
-------------------------------------------------------------------
The pertinent part of the Java test is here:
-------------------------------------------------------------------
// key creation outside of timed loop
String[] keys = new String[50000];
for (int i=0; i<50000;i++)
keys[i]="k"+i*777;
long t1 = System.currentTimeMillis();
HashMap map = new HashMap(50000);
for (int i=0; i<50000; i++)
map.put(keys[i],"hello");
long t2 = System.currentTimeMillis();
-------------------------------------------------------------------
_______________________________________________
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.