perl_devel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am working on a Perl application which gives method calls to Java API Methods using Inline::Java modules . The application works fine by giving expected results but when i replicate a similiar call using java itself and do a time comparison, I find a considerable amount of time difference.
What could be the reason?
Any ideas as to how to improve ?
Is there any other way apart from using Inline::Java module to call java methods?
Regards

Replies are listed 'Best First'.
Re: Calls to Java methods
by krisahoch (Deacon) on Jun 03, 2005 at 16:51 UTC
    Hi perl_devel

    You may find that it takes a bit longe while to run the Perl with Inline::Java, than it takes to run the Java code with the JVM. The reason for this is because Inline::Java takes your code: creates an appropriatly name java source file, compiles it, imbedds it, runs it and makes whatever calls it needs to make.

    This is slower because Inline::Java has a bridge that acts like a go-between for Perl and Java. So the Java code is running at normal speed, and the perl is running at normal speed. The hit comes in when the Perl code has to wait for the Java code:D

    Kristofer Hoch
Re: Calls to Java methods
by Grygonos (Chaplain) on Jun 03, 2005 at 13:26 UTC

    This is probably a bad idea, but it's just something I thought of. You could potentially setup an event handler in a standalone Java app that waits for an event that perl can fire. i.e. a file with a certain name gets created in a directory, then java's event handler fires and it knows to do it's thing. The Java method could then (again possibly but probably a horrible idea) write out a file to that same directory with a "requestid" in the file name so that perl knows when to stop monitoring that directory for the java functions output.

    Again this is most likely an incredibly horrible idea, but it's just an option.
Re: Calls to Java methods
by brian_d_foy (Abbot) on Jun 04, 2005 at 03:36 UTC

    If you want to run perl and and java, you have to expect it to be slower than running just one of them. Even if you call out to an external java program, that's still going to be slower than either a pure Perl or pure Java implementation.

    How big of a time difference do you see? How is that compared to the total run time in either implementation?

    --
    brian d foy <brian@stonehenge.com>