Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: C, MathLink or Java, J/Link

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28207] Re: C, MathLink or Java, J/Link
  • From: tgayley at wolfram.com (Todd Gayley)
  • Date: Wed, 4 Apr 2001 04:13:28 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <99usl9$61j@smc.vnet.net> <9a1jfh$9o8@smc.vnet.net> <9a6dps$eo2@smc.vnet.net> <9absfe$jvl@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 3 Apr 2001 03:01:02 -0400, Jens-Peer Kuska <kuska at informatik.uni-leipzig.de> wrote:

>Hi Todd,
>
>yes your J/Link *is* great. It is one of the best perls of software
>that I have seen!
>And the best thing on it, that you can use Java without programming
>in Java.

Thanks for your support of J/Link. The Mathematica community is also in debt to you for
your excellent (and free) MathGL3d.

>I have two questions to the benchmark, you gave. What C-compiler ?
>On Intel boxes Intel 4.5 is usual 20-30 % faster than Microsoft's
>Visual C. Even the code generated by Borland C 5.5 is better that
>Mircosoft's.

I used Microsoft Visual C++. There may be compilers out there that can produce faster
code, but does it matter? The fact that Java and C are in the same ballpark on this
program is enough to make my point. What fraction of users out there are going to switch
away from Visual C++ because another compiler produces code that runs a little faster?
Certainly not me. People who care about that level of performance are not going to be
using Java. I'm much more interested in using tools that I like, am comfortable with, and
am productive with. My personal productivity is _far_ more important to me than shaving a
few points off a timing. I'll wager that this is true for the vast majority of Mathematica
users (that's why they use Mathematica).

>And how does Mathematica with the code ? using all the optimizations
>that Mathematica can do ? How fast is Mathematica itself with
>the benchmark ?

Well, I don't have the motivation to put in the effort to produce an optimized Mathematica
program for this. I did a literal translation of the C/Java code into Mathematica
(resulting in a very naive Mathematica program), and it ran 8000 times slower than the
fastest Java and C timings. It could be made much faster with a little work.

>> Are these results typical of numerical programs of the sort Mathematica programmers are
>> likely to be writing? I would say yes. I usually expect a Java program to run in a range
>> comparable to C down to perhaps 1/2 to 1/3 as fast.
>
>Hoops ! you mean a C program on a 1.4 GHz PC is as fast as a Java
>program
>on a 2.8 or 4.2 GHz PC ... So where to buy the 4.2 GHz PC ??
>
>If this *is* not slow, what else mean "slow" ? For me it make
>a difference if I have to wait one hour or three. 
>
>I have seen people that work hard for 5 % performance gain.

If your definition of slow is that Java runs at half the speed of C, then yes, Java is
slow. If I can work in a language where I am much more productive and can ignore the
intricacies of MathLink entirely, and the cost is only that my programs run at the same
speed that my C programs ran 18 months ago (i.e., Moore's Law), then I am happy to do
this. 

I just got a 1.2 GHz machine. It's 2.5 times as fast as my 500 MHz machine, but I would
hardly say that my old machine is suitable only for Tic Tac Toe.

People writing programs that take one hour to run will probably want to use C. People who
are willing to work hard for a 5% performance gain will probably use C. Most other people
will be happy with Java.

>> 
>> As always, "Your mileage may vary". Nevertheless, people should not rule out Java in
>> advance as a language for virtually any kind of program based on the (mostly erroneous)
>> assumption that it is "too slow".
>
>I agree with you that in many cases speed is a so critical point.
>Since the computer spend the most time while waiting onto a mouse click
>or a keyboard character. So for those cases Java is a lot easyer than
>C or C++.
>
>But you should keep in mind what happens with an application.
>If the code is fast, one find always a task that can be done also.
>Every program is extended until the program hit the limits of the
>computer.

Agreed, but I am just repeating myself. Some programs stretch the limits of the machine.
Most don't.

>> 
>> As for the original question, about whether to use Java or C for an algorithm to be called
>> from Mathematica, the answer is of course "it depends". Some factors that favor C are:
>> 
>> - you already are proficient in C
>> - you just have one function to call and you don't need to have a
>>   complicated interaction with Mathematica
>> - you don't need to port your program to other platforms
>> - flat-out performance is overwhelmingly important
>> 
>
>The easy usage for complicated interaction with Mathematica
>is your merit. And it is up to every C-programmer
>to do similar stuff in C/C++. Your Java/C source is about
>500 kByte. This is the real advantage of Java -- that you
>have done a lot of work on it. But how much of this Java
>code is used by a typical MathLink application ?
>The most MathLink programms are written for speed. 
>I expect the advantage of Java in writing custom 
>portable user interfaces for all those people that 
>need more than some buttons and in this case speed is not
>critical and one has the Java librarys.
>
>I think "portability" is not more a serious problem 
>of a C program. MathLink is wonderful portable and 
>one finds for almost every thing a portable library.

Most MathLink C/C++ programs are very portable. But that still means that you have to have
access to machines that run every OS you want to support, you have to master the
development environments on these machines, you have to recompile on every platform every
time you make a change, etc. This is not an issue for users who are just building programs
for one machine, but for those who want to produce something useful for a variety of
platforms, it is a huge consideration.

I'm sure we are both aware that we are just rehashing a debate that has gone on about new
languages and programming styles since the dawn of programming. People said C was slow
compared to assembly language. C won out because it was more productive to work in, was
portable, and got faster as compilers improved.

I think we can just agree to disagree about the usefulness of Java for general-purpose
programming tasks. The performance of Java is considered acceptable by the huge number of
developers doing commercial and research programming with it. My opinion is that for
people who are not overwhelmingly concerned about performance, Java is the best choice for
programs that call, or are called by, Mathematica. But people shouldn't take my word for
it--try it!


--Todd Gayley
Wolfram Research


  • Prev by Date: Re: Re: C, MathLink or Java, J/Link
  • Next by Date: Problem with InverseFunction
  • Previous by thread: Re: Re: C, MathLink or Java, J/Link
  • Next by thread: Polar Grids in Mathematica