Re: Java vs C/Objective-C performance question
Re: Java vs C/Objective-C performance question
- Subject: Re: Java vs C/Objective-C performance question
- From: John Hörnkvist <email@hidden>
- Date: Mon, 17 Mar 2003 12:36:42 +0100
On Monday, March 17, 2003, at 08:34 AM, Sheehan Olver wrote:
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.
Why not? It happens now and then. In this case, it's probably the
"count++" pattern; that is a common problem in C compilers.
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.
You send three Objective-C messages for each Java constructor call.
That looks like a good deal of extra overhead to me.
However, this looks like a scenario where automatic garbage collection
would a huge win. Remember that in many garbage collectors, the
performance is mostly proportional to the amount of live data not the
amount of garbage! In this case, your live data set is extremely small,
so garbage collection cost is tiny.
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).
It's educational to replace "count++" with "++count" in the C code:
2003-03-17 10:41:55.304 test[1877] Before 1: 2003-03-17 10:41:55 +0100
2003-03-17 10:41:57.992 test[1877] After 1: 2003-03-17 10:41:57 +0100
2003-03-17 10:41:57.994 test[1877] Before 2: 2003-03-17 10:41:57 +0100
2003-03-17 10:42:27.677 test[1877] After 2: 2003-03-17 10:42:27 +0100
Then, to see what the messaging cost is, do IMP caching, and use
allocWithZone: instead of alloc on the allocation part:
2003-03-17 10:50:35.846 test[1908] Before 1: 2003-03-17 10:50:35 +0100
2003-03-17 10:50:38.463 test[1908] After 1: 2003-03-17 10:50:38 +0100
2003-03-17 10:50:38.465 test[1908] Before 2: 2003-03-17 10:50:38 +0100
2003-03-17 10:50:59.895 test[1908] After 2: 2003-03-17 10:50:59 +0100
Then, to find out where time goes, replace the alloc/init/release with
malloc/free
2003-03-17 11:54:32.801 test[2152] Before 1: 2003-03-17 10:54:32 +0100
2003-03-17 11:54:35.593 test[2152] After 1: 2003-03-17 10:54:35 +0100
2003-03-17 11:54:35.595 test[2152] Before 2: 2003-03-17 10:54:35 +0100
2003-03-17 11:54:51.000 test[2152] After 2: 2003-03-17 10:54:50 +0100
This is compiled with "cc -o test test.m -Os -mcpu=7400 -framework
Foundation", on an PowerMac G4 400.
(With my research compiler --- which compiles an object oriented
language with dynamic dispatch --- the alloc/release loop runs in less
than 2 seconds optimized, and about 5 seconds unoptimized.)
Regards,
John Hornkvist
_______________________________________________
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.