Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Runtime speed of java vs. Objective C Code

Runtime speed of java vs. Objective C Code
Thread Tools
Vax
Junior Member
Join Date: Oct 2001
Location: Osnabrueck, North Germany
Status: Offline
Reply With Quote
Oct 22, 2001, 12:01 PM
 
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
Reply With Quote
Oct 22, 2001, 12:54 PM
 
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
Reply With Quote
Oct 22, 2001, 06:56 PM
 
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
Reply With Quote
Oct 23, 2001, 09:35 AM
 
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
Reply With Quote
Oct 23, 2001, 05:43 PM
 
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
Reply With Quote
Oct 24, 2001, 04:38 PM
 
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
     
Vax  (op)
Junior Member
Join Date: Oct 2001
Location: Osnabrueck, North Germany
Status: Offline
Reply With Quote
Oct 24, 2001, 07:44 PM
 
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 :-&gt; !!!

Greetings Vax
--:: Insanity is also a state of mind ::--
     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Oct 24, 2001, 11:30 PM
 
sweet, thanks for the help!
     
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
Oct 25, 2001, 03:51 AM
 
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
Reply With Quote
Oct 26, 2001, 05:59 AM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:31 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2