Re: In which cases/problems is Prolog faster than Java?
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 20 May 2008 09:14:30 GMT
On 2008-05-20, Bart Demoen <bmd@xxxxxxxxxxxxxxxxx> wrote:
Christina wrote:
Does minimax algorithm work faster in Prolog than in Java?
Some 10 years ago, when Java was only byte-code emulated, there was a
paper (or tech report) by (I think) Spanish people (UPM probably) who
showed with some benchmarks that Java and Prolog had roughly the same
performance (on some benchmarks, including qsort if I remember
right). I repeated some of those benchmarks myself at that time and it
depended a bit on which Prolog system one uses, and how one writes
particular constructs (if-then-else or multiple clauses with cut for
instance), but Java and Prolog were indeed close in speed.
In the mean time, Java execution technology has moved to JIT with
accordingly higher performance, while Prolog has mainly stayed
emulated. So you should expect that Java implementations are faster
(by an order of magnitude) than Prolog implementations. And that's all
you will be able to compare anyway: one implementation versus another
implementation, not one language versus another language. It's all in
the compiler technology that is used, nothing intrinsic in the
language, at least not for toy benchmarks where "everything is known".
To match the speed of Java (or other procuedural languages with unsafe
arithmetic) you have to do a lot of work. You need some form of JIT
and global analysis. I once benchmarked a little program doing a lot
of integer arithmetic and it turned out it was spending most of its
time in the (C) low level addition and multiplication functions doing
the actual work, just because it needs to do all the overflow checking
switching between C bounded arithmetic and unbounded arithmetic. Only
a global analysis that can do a check at entry of the loop and fall
back to a fast algorithm without these checks if conditions are met.
This seems language dependent. If the language doesn't guarantee safe
arithmetic the programmer is responsible (and cleverly moves the check
outside the loop or `forgets' about it all along), otherwise the
implementation. Ok, the Prolog standard allows for both. SWI-Prolog
implements safe arithmetic.
Another example is merge-sort. Implemented straightforwardly in
Prolog, it will produce a lot of garbage lists in the process. That
way you'll never win using Prolog. Not allowing destructive
assignment makes the language less vulnerable for programming
mistakes, but it also makes (some) algorithms slower. Only analysis
may be able to translate the one into the other, providing both good
performance and safety.
All in all though, performance generally isn't that important. The
simple fact that the slowest implementation of Prolog is the most
popular indicates there are other implementation/community aspects
that matter more :-)
Cheers --- Jan
.
- References:
- In which cases/problems is Prolog faster than Java?
- From: Christina
- Re: In which cases/problems is Prolog faster than Java?
- From: bart demoen
- Re: In which cases/problems is Prolog faster than Java?
- From: Christina
- Re: In which cases/problems is Prolog faster than Java?
- From: Bart Demoen
- In which cases/problems is Prolog faster than Java?
- Prev by Date: Re: get unused integer
- Next by Date: Re: In which cases/problems is Prolog faster than Java?
- Previous by thread: Re: In which cases/problems is Prolog faster than Java?
- Next by thread: Re: In which cases/problems is Prolog faster than Java?
- Index(es):
Relevant Pages
|