Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JVM Prolog Performance

271 views
Skip to first unread message

Jan Burse

unread,
Nov 13, 2012, 11:49:49 AM11/13/12
to
Blog entries for the Swing/Hotspot Metal:

Jekejeke < Jinni
1 : 40
https://plus.google.com/u/0/103259555581227445618/posts/TebD9ywKeHk

Jekejeke < JLog < tuProlog < JIProlog
1 : 6 : 13 : 16
https://plus.google.com/u/0/103259555581227445618/posts/HXy9knrnWYq

Unfortunately the situation is not that good
on the Android/Dalvik platform. Tests usually
run 100 times (sic!) slower.

But anybody about to beat it on the Swing/Hotspot Metal?

Definition of JVM Prolog is a Prolog
that is implemented as a JVM Language:

"This list of JVM languages comprises computer programming languages
that are used to produce software that runs on the Java Virtual Machine
(JVM). Some of these languages are interpreted by a Java program, and
some are compiled to Java bytecode and JIT-compiled during execution as
regular Java programs to improve performance.".
(From http://en.wikipedia.org/wiki/List_of_JVM_languages )

Bye

P.S.: Troll disclaimer: Yes I know these are micro
benchmarks. And no I don't think competition is bad,
in the end the end-user will profit. And I am also
an end-user but in the same time subject to it.

Paul Tarau

unread,
Nov 14, 2012, 1:07:50 AM11/14/12
to
Jinni Prolog has a compiled mode and a 1-2 orders of magnitudes slower interpreted mode. (re)consult/1 is used to load interpreted code - keep that in mind when testing for performance. Compiled code is loaded with the usual ?-[file] syntax.

Also make sure you get the compiler from

http://code.google.com/p/jinniprolog/

and not an older interpreted version that used to have the same name.

Paul Tarau

Jan Burse

unread,
Nov 14, 2012, 6:42:04 AM11/14/12
to
Hi,

I used:

$ /Library/Java/JavaVirtualMachines/1.7.0u.jdk/Contents/Home/bin/java
-jar prolog.jar nl
Loading Prolog bytecode from Java classes.

Starting Jinni Java-based Prolog Compiler version 12.02
Copyright (C) Paul Tarau 1999-2012

So I guess this is the newest version. I then used
the Compile button in the GUI version. But the
file I compiled contained consult/1 invokations.

Should I simply replace consult/1 by compile/1?

Bye


Paul Tarau schrieb:

Paul Tarau

unread,
Nov 14, 2012, 8:53:43 AM11/14/12
to
The best way to invoke Jinni is:

java -cp ./prolog.jar prolog.kernel.Main ./prolog.jar

You might need to adjust the "./" path to where prolog.jar is located.

That gives you an editable "command line" and the classic ?- prompt.

Then, use compile/1 to load your favorite benchmark. For instance,

nrev.pro in directory

/MainProlog/bin/progs

will give around 10+ million LIPS on my Mac Air (that's slightly faster than C-based SWI-Prolog, but Jinni is usually slower than SWI on most other tasks)

?- compile(nrev).
begin_compiling(to(mem),nrev)
end_compiling(time(214,msec),nrev)
yes

?- big.

'BMARK_brev_100_times_3000_elem_nrev:' = [klips = 13579.08611599297,time = 1.138,length = 100,iterations = 3000,heap = 15650,trail = 0,stack = 0]
yes

Paul

Jan Burse

unread,
Nov 14, 2012, 10:24:38 AM11/14/12
to
Paul Tarau schrieb:
> You might need to adjust the "./" path to where prolog.jar is located.
>
> That gives you an editable "command line" and the classic ?- prompt.

I tried already the classic prompt. But there is a problem
with file locations. I cannot use absolute paths:

?-
compile('/Projects/Jekejeke/Prototyping/headless/jekdev/demo/benchmark/jinni.p').
begin_compiling(to(mem),'/Projects/Jekejeke/Prototyping/headless/jekdev/demo/benchmark/jinni.p')
prolog.kernel.Machine prolog 0 returned::
exception(error(file_or_url_not_found('/Projects/Jekejeke/Prototyping/headless/jekdev/demo/benchmark/jinni.p'),tried(home('./'),prefixes(['','agentlib/','classlib/','vprogs/','progs/','../psrc/']),sufixes(['.pl','','.pro']))))
Restarting Prolog Machine: prolog.kernel.Machine prolog 0

In the GUI version, there is no path problem. Provided I load the
file which contains the compile statements in the editor and
the press the compile button. The is also a path problem when
using the query text field.

Bye

Jan Burse

unread,
Nov 14, 2012, 10:38:26 AM11/14/12
to
Jan Burse schrieb:
> Provided I load the file which contains the compile statements
> in the editor and the press the compile button.

Containing the compile/1 statements does also not work.
At least judging from the following errors:

Undefined after :-, code[52457..52873] ->serialize/101
Undefined after :-, code[52469..52873] ->new_engine/50
Undefined after :-, code[52496..52873] ->serialize/101
Etc..

Bye

Jan Burse

unread,
Nov 14, 2012, 10:56:33 AM11/14/12
to
Paul Tarau schrieb:
> The best way to invoke Jinni is:
>
> java -cp ./prolog.jar prolog.kernel.Main ./prolog.jar
[...]
> ?- compile(nrev).
> begin_compiling(to(mem),nrev)
> end_compiling(time(214,msec),nrev)
> yes

Moving an renaming will also not work. I have moved
and renamed mtak.p. But still cannot compile it on
a Mac:

$ /Library/Java/JavaVirtualMachines/1.7.0u.jdk/Contents/Home/bin/java
-cp ./prolog.jar prolog.kernel.Main ./prolog.jarLoading Prolog bytecode
from Java classes.
[...]
?- compile(mtak).
begin_compiling(to(mem),mtak)
prolog.kernel.Machine prolog 0 returned::
exception(error(file_or_url_not_found(mtak),tried(home('./'),prefixes(['','agentlib/','classlib/','vprogs/','progs/','../psrc/']),sufixes(['.pl','','.pro']))))
Restarting Prolog Machine: prolog.kernel.Machine prolog 0
?- ^D
Prolog execution halted. CPU time = 7.888
expand/shrink time=0 GC time:0
$ ls -la bin/progs/mtak.*
-rw-r--r-- 1 xxx yyy 484 27 Okt 20:39 bin/progs/mtak.pl

On the other hand compile(nrev) works. Is nrev.pl inside
prolog.jar?

Bye


Jan Burse

unread,
Nov 14, 2012, 11:01:17 AM11/14/12
to
Jan Burse schrieb:
> On the other hand compile(nrev) works. Is nrev.pl inside
> prolog.jar?

Yes I made a little test. I removed qsort.pl from
the directory MainProlog/bin/progs and compile(qsort)
still found it.

(Could be a problem from building the .jar. Happens
also to me. Some IDE copy resources into the classes
directory, and then stuff might land in .jar files)


Paul Tarau

unread,
Nov 14, 2012, 2:56:51 PM11/14/12
to
You can place prolog.jar in ~/bin together with a script called "jinni" containing

java -cp ".:$HOME/bin/prolog.jar" prolog.kernel.Main $HOME/bin/prolog.jar $1 $2 $3

that's also in ~/bin.

Assuming ~/bin is in your PATH, then you can run it by typing "jinni" from any place. You can compile files using

?-[myfile].

or

?-['myfile.mysuffix'].

Paul

Jan Burse

unread,
Nov 14, 2012, 4:05:49 PM11/14/12
to
Paul Tarau schrieb:
> -cp ".:$HOME/bin/prolog.jar" prolog.kernel.Main $HOME/bin/prolog.jar $1 $2 $3

Thanks for your patience with me squab chick here.
I guess the . does it. Now something happens:

?- [test].
begin_compiling(to(mem),[test])
end_compiling(time(12,msec),[test])
yes

?- hi.
hello
yes

But qsort is still magically in the search path:

?- [qsort].
error in engine prolog.kernel.Machine prolog 0:ask()=>ip=34435,cell=2:
'!! Prolog_Error'('TypeException','invalid update attempt to:
<predmark/0,time/2>==>26802:(0)'')
begin_compiling(to(mem),[qsort])

Can I switch this off?

But the good thing is absolute paths now work also:

?- ['/Projects/[...]/benchmark/jinni.p'].
Exception in thread "main" java.lang.NullPointerException
at prolog.logic.HeapStack.pushTerm(HeapStack.java:124)
at prolog.logic.HeapStack.newVar(HeapStack.java:135)
at prolog.logic.LogicEngine.INIT_INTERP(LogicEngine.java:151)
at prolog.logic.LogicEngine.load_engine(LogicEngine.java:1779)
at prolog.kernel.Shell.send_query(Shell.java:80)
at prolog.kernel.Shell.shell_step(Shell.java:105)
at prolog.kernel.Shell.run(Shell.java:144)
at prolog.kernel.Main.main(Main.java:482)

But why the NullPointerException? jinni.p reads as follows:

uptime(X) :-
statistics(runtime, [X|_]).

gctime(0).

% [...]

Whats wrong with the above? I guess the problem is the
ending comment in the Prolog text. (Syntax Syntax
-> Ulrich do you have a test case?)

When I restart jinni, and don't consult my jinni.p, and
directly consult commonshort.p, I get the following:

?- ['/Projects/[...]/benchmark/commonshort.p'].
Undefined after :-, code[52520..52770] ->uptime/2
begin_compiling(to(mem),['/Projects/Jekejeke/Prototyping/headless/jekdev/demo/benchmark/commonshort.p'])
end_compiling(time(114,msec),['/Projects/Jekejeke/Prototyping/headless/jekdev/demo/benchmark/commonshort.p'])
yes

Is the "Undefined after :-, code[52520..52770] ->uptime/2" a
ignorable warning? Or does it indicate that uptime is missing?
How can I then compile mutually recursive predicates residing
in different files?

Bye


Jan Burse

unread,
Nov 14, 2012, 4:26:55 PM11/14/12
to
Hi,

After some experimenting I could also obtain Jinni
compiler figures. The results of a warm run are
shown below. I have contrasted the results to Jekejeke
Prolog which is an interpreter only. I have added an
additional column showning the number of used iterations
for the corresponding test program (*):

Jekejeke Jinni Iterations
nrev 114 ms 31 ms 601
crypt 97 ms 51 ms 31
deriv 74 ms 153 ms 3001
poly 79 ms 88 ms 6
qsort 113 ms 104 ms 601
tictac 121 ms 169 ms 1
queens 136 ms 72 ms 2
query 156 ms 174 ms 301
mtak 98 ms 111 ms 3
perfect 115 ms 242 ms 2
calc 111 ms 165 ms 2001
Total 1214 ms 1360 ms

Conclusion the real jet JVM Prolog system is
not yet born. We are all still flapping. Should
join forces and create a Jekejin blending best
of the corresponding interpreter and compiler
technology, maybe will beat YAP.

But nevertheless Jinni performs well. Will
probably move to test more compilers in the
future, eventually kick out SICStus interpreter
from my regular testing and add Jinni. And
another compiler as well. I guess can learn
something.

(*)
Source code of the test cases for reproducibility
can be found here:
http://www.jekejeke.ch/idatab/doclet/blog/en/docs/std/06_bench/09_programs/package.html

Metal used for testing: Mac OS X Version 10.6.8
2.4 GHz Intel Core i5, 4 GB 1067 MHz DDR3
OpenJDK Runtime Environment (build 1.7.0-u4-b225-20120119)
OpenJDK 64-Bit Server VM (build 23.0-b10, mixed mode)
Jekejeke Prolog 0.9.6
Jinni 12.02

P.S.: Side note, it is seen that Jini compiles
to byte code (I assume, and I interpret the result
as such). Since the difference between warm and
cold run is much higher for Jini than for Jekejeke:

Warm Cold Percent
Jini 1360 2359 173%
Jekejeke 1214 1989 163%

But this only a speculation. And the skew can
be probably better measured by using less
iterations.

Jan Burse schrieb:

Jan Burse

unread,
Nov 14, 2012, 4:29:23 PM11/14/12
to
Jan Burse schrieb:
> But this only a speculation. And the skew can
> be probably better measured by using less
> iterations.

And Jekejeke uses also some JIT technology
in the interpreter implementation (PICs for
predicate lookup, dynamic cascaded indexes), so
it has also a pronounced cold and warm difference.

Bye

Jan Burse

unread,
Nov 23, 2012, 1:42:42 PM11/23/12
to
Here is a funny code, Scheme in one class:
http://kenai.com/projects/ninja/sources/sioc-repo/content/src/sioc/SIOC.java?rev=7

Makes also use of some invoke magic. But I guess
the package name java.dyn is outdate. Looks like it
is called java.lang.invoke now:
http://docs.oracle.com/javase/7/docs/api/java/lang/invoke/package-summary.html

Jan Burse schrieb:

Jan Burse

unread,
Nov 28, 2012, 2:00:10 PM11/28/12
to
Hi

How about Paul Fodors OpenRuleBench.
Done some testing with Jinni?
I am refering to:

http://rulebench.projects.semwebcentral.org/

Did not yet touch.

Bye


Paul Tarau schrieb:
> Styla is an interpreter only, but it might end turned into a compiler one day - somewhat similar to Jinni's, but simpler, "goal stacking" based.
>
> On the Pereira benchmark at:
>
> http://code.google.com/p/styla/source/browse/progs/pbm.pro
>
> Jinni Prolog is about 4 secs, Styla is about 18 on my Mac Air.
>
> Paul Tarau
>
> P.S. As functional-style Scala with case classes transliterates almost one-to-one to/from deterministic Prolog and built-ins are just "drop-ins", one can still develop fast "logic programming" applications by easily combining the two languages.


0 new messages