Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question



James Mooney wrote:
|Well let me give you an example and perhaps thing become clearer.
|
|I wrote two apps......basic command line style with no gui.
|
|One was written is Java and one is straight C (carbon api)
|
|Each did the same thing....takes an image, calls quicktime to decode the
|image data, recompress the image data into a newly resized jpg.
|
|Each was tested and the C app took about a half a second and the Java
|one took about 10 seconds. Mind you I did not implement QT in the Java
|one. I fed the app a jpg and just asked it to resize the image and
|store it again.
|
|On top one would think the Java app had a lot less work to do. But do
|to what I assume was the sluggish running of Java Runtime. I would
|expect this.
More likely, the extra time was spent "booting" the Java Virtual Machine (the JVM that people speak of every so often). I'd guess that if you arranged to time the actual working part of the programs, they wouldn't show the dramatic difference you're seeing.
The problem here is that the program just doesn't run long enough to see the real speed difference between the two languages. Why might that matter? Consider this: an airplane travels *much* faster than a car. However, if you wanted to go across town, you'd use a car, not an airplane. Because of the way airplanes are used, there's a large "startup cost" with an airplane--getting a ticket, waiting at the gate, going through security, etc.--that just isn't there with a car. Using an airplane to go across town would probably take rather *longer* than using a car. But make the trip long enough--go across the country--and the airplane's speed becomes apparent: no car could cross the country in five hours.
Also, since the real work is done by QuickTime, the two programs are probably really just different ways of calling the same QuickTime code. All the programs do is coordinate the calls to QuickTime. This further hides any real difference there might be between Java and C, because the running time of *your* code is probably approaching "too short to measure".
Generally, when people want to know "is X or Y faster?", they're talking about programs that run for several minutes, if not hours or days or weeks. For programs that run for a second or so, the startup time can swamp the actual time it takes for the program to run, and makes the comparisons pretty much meaningless. (This means that, for short programs, a language like Perl or Ruby can get the work done sooner, because they start up much faster.)
Also, C and Objective-C won't necessarily run at the same speed. Objective-C programs are going to include many, many method calls, which will incur a time penalty that plain vanilla C won't. Hence, the pure C program will probably run somewhat faster. (Measurably faster? Possibly not, depending on how each program is written, and how long they run.)

|My original question is directed to how Java is implemented in Cocoa.
|What is the end product, a compiled app, or a collection of byte code
|and library files that will need to be passed through a Java engine to
|run (hence a performance hit).
Again, it depends on whether you're talking about a Java program that uses the various Java NSWhatever classes in the com.apple.cocoa package, or an Objective-C program that uses a few Java classes here and there. The first is compiled into bytecode and interpreted by the Java JVM; the second is (mostly) compiled into straight machine language, with suitable connections to the JVM where necessary. (Experts, feel free to correct me if I've got this wrong.)

|I realize Sun would probably hate Apple doing that but it would seem
|like a great tool if Java apps ran native code upon a recompile....ie
|set target to byte code or machine code........
To a considerable degree, this is already how things work. The current design of the JVM uses a technique known as "just-in-time compiling". As the JVM interprets the bytecode, it notices which methods get called frequently, and it *does* compile those methods to native code. From that point on, the native code is run when the method is executed, and the bytecode is ignored. (And Sun won't hate Apple for this, because Sun designed the JVM. Apple is only supplying the PPC-specific parts of the just-in-time compiler.)

Glen Fisher
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Newbie question (From: James Mooney <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.