 |
 |
Runtime speed of java vs. Objective C Code
|
 |
|
 |
|
Junior Member
Join Date: Oct 2001
Location: Osnabrueck, North Germany
Status:
Offline
|
|
Hello,
I have one question about the runtime speed of compiled cocoa software under OS X.
Is there any runtime speed difference between Java or Objective-C coded programms?
Or do they run at the same speed?
Greetings Vax
|
|
--:: Insanity is also a state of mind ::--
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Java with swing is painfully slow.
Java with Cocoa is slower than Obj-C with Cocoa, and if you use Obj-C with Cocoa you can do lots of the logic in C, which is known to be very fast (and you could embed assembly in it, too, if you wanted).
Anyway, compare the Java and Obj-C versions of Sketch for a general overview of speed, it was architected to be functionally the same in both languages.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Status:
Offline
|
|
Originally posted by Angus_D:
<STRONG> (and you could embed assembly in it, too, if you wanted).
</STRONG>
How, (if you don't mind me asking) would one go about embedding assembly in a cocoa program? I have yet to attempt it, but it would be very useful for what I am working on.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
How, (if you don't mind me asking) would one go about embedding assembly in a cocoa program? I have yet to attempt it, but it would be very useful for what I am working on.
Probably the same way you'd embed it in any other C program.
Unfortunately, I don't know what that method is. But with ObjC being a superset of C, it seems that this should work. Anyone here able to help with this?
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status:
Offline
|
|
You cannot embed assembly in C directly, you can embed it in C++. The asm keywork is used to embed assembly instructions in C++ code. The asm keyword is added by C++, it may work in the Obj-C compiler too, but not in plain C. It can be confusing since you can use a C++ compiler to compile a C program, and some compilers don't switch off C++ features when compiling C. For instance the '//' (C++) style of comment was not part of the C language until '99 (or '98, I'm not exactly sure), but many compilers allowed it since it is part of C++.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
Originally posted by LordJavac:
<STRONG>You cannot embed assembly in C directly, you can embed it in C++. The asm keywork is used to embed assembly instructions in C++ code. The asm keyword is added by C++, it may work in the Obj-C compiler too, but not in plain C. It can be confusing since you can use a C++ compiler to compile a C program, and some compilers don't switch off C++ features when compiling C. For instance the '//' (C++) style of comment was not part of the C language until '99 (or '98, I'm not exactly sure), but many compilers allowed it since it is part of C++.</STRONG>
//-style comments are a very common extension to C, and so is inline assembly, and you can use both in a C program as long as your compiler supports those (and gcc does both). The fact that those work in a C program in no way implies that the compiler is in C++ mode; if you want to prove this to yourself, run the line printf("%u\n", (unsigned)sizeof 'a'), which will print 4 in C mode and 1 in C++ mode on the PowerPC.
asm made it into the C99 ANSI C standard, btw.
Here's a simple example of a program that uses inline assembly that I wrote a while back. Type in an integer and hit return; it will print the factorial of that integer.
http://www.people.cornell.edu/pages/pa44/asm.c
-Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Oct 2001
Location: Osnabrueck, North Germany
Status:
Offline
|
|
Ok, ok,
but my question was is it real java code, that is compiled or is it only java programming language and then compiled to normal code?
Any real answer would be fine :-> !!!
Greetings Vax
|
|
--:: Insanity is also a state of mind ::--
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Status:
Offline
|
|
sweet, thanks for the help!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
Angus_D opined:
<STRONG>Java with swing is painfully slow.</STRONG>
I used to think this too. Now i just think it's annoyingly slow - provided you know how to use it.
The trick is with Threads. If you need to do anything at all time-consuming, don't do it on the Swing thread - either keep a daemon running or spawn an extra thread to do it instead.
Yes, it's a lot of work, but it does make a difference.
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status:
Offline
|
|
Originally posted by Vax:
<STRONG>but my question was is it real java code, that is compiled or is it only java programming language and then compiled to normal code?</STRONG>
It's using the official javac, so it's compiled for the Java VM. Mac OS X 10.1 uses the HotSpot engine, which compiles the VM-code into native at runtime (and uses it every time that part of the code is reached). It should theoretically improve the speed.
But I'd rather not bother with writing Java code for Mac OS X-apps.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|