I didn’t have nearly as much faith in Objective-C. I figured that Java would beat it by at least 2x. So much thought has been put into Java VMs compared with the Objective-C runtime it would actually be a shame if Objective-C won this competition. The benchmark I grabbed was a benchmark we use to test JRockit against HotSpot. Its does string comparisons that result in the different cases. Universally people thought this would give Obj-C an edge because strings are so low level in C. However, that is misleading, because a string in Obj-C isn’t low level at all. Its a class, NSString, just like it is in Java. Well, here is the result of the benchmark on a 1.42ghz PowerMac G4 (similar results on my 1.5ghz Powerbook):

That’s a nice 6.4x speedup for applications that use a lot of strings! Here is the binary you can run right off this site:
BenchmarkApp.zip
Here is the Xcode project so you can see the source and build it yourself:
Benchmark.zip
I would normally now talk about how this whole thing took like 20 minutes to develop, including the user interface, but the only people that would care are people that already know how productive development is when using Xcode + IB + Cocoa. You might also take note that you can put both Obj-C and Java in the same executable without any trouble, just make sure you start with a Cocoa-Java application. Oh, one more thing, I also tried compiling it optimizing for speed instead of space — it ended up with the same benchmark result except the executable was smaller!?
UPDATED
After that experiment I talked to a Cocoa person and he said that many times people will go back and optimize all their code for manipulating strings and things like that using pure C code. So I rewrote the benchmark again, this time using standard ANSI C. Its a straight console application and here are the results:
/Users/sam/Projects/Xcode/Benchmark:> gcc -o benchmark benchmark.c; time ./benchmark
53678.991685
real 0m18.640s
user 0m17.480s
sys 0m0.200s
Without optimizations, the C application is actually a lot slower than the Java application. Lets add some optimizations:
/Users/sam/Projects/Xcode/Benchmark:> gcc -O3 -o benchmark benchmark.c; time ./benchmark
69006.049967
real 0m14.502s
user 0m14.230s
sys 0m0.050s
Still lags slightly. I’m sure there is probably some command line thing that could get the performance to exceed the Java version, however, I think my point is made. Java is really, really quite fast. So please Apple, stop using an inferior development laguage. Here is the C file:
benchmark.c.zip
