PL/SQL Vs. Oracle JVM: Speed Comparison for Mathematical Operations…

I remember hearing someone talking about this years ago and I never actually took the time to check it out. It looks like the real answer is “it depends”. For the basic loop processing and maths the JVM does look a little faster. It was just a curiosity thing, but I thought I might as well write it up as an article on the website.

Cheers

Tim…

Author: Tim...

DBA, Developer, Author, Trainer.

6 thoughts on “PL/SQL Vs. Oracle JVM: Speed Comparison for Mathematical Operations…”

  1. Hey Tim – no fair!!!

    FOR i IN 1 .. 1000000 LOOP
    … plsql stuff …
    END LOOP;

    DBMS_OUTPUT.put_line(‘PL/SQL (‘ || p_operation || ‘): ‘ || (DBMS_UTILITY.get_time – l_start) || ‘ hsecs’);

    l_start := DBMS_UTILITY.get_time;

    FOR i IN 1 .. 1000 LOOP
    … java stuff …
    END LOOP;

    when you multiple the java timings by 1,000 more – you might see a different difference!!!!!!!

  2. Sure enough, when you compare apples with apples it looks kinda different. Thanks for spotting the “deliberate” mistake… 🙂

    Cheers

    Tim…

  3. Hi!

    The 11g (R1) docs say that arithmetic operations on SIMPLE_INTEGER use hardware ops directly if the code is natively compiled, which implies that this is not the case in your example (see http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/whatsnew.htm#g1769644):

    “Without the overhead of checking for nullness and overflow, these subtypes provide significantly better performance than their base types when PLSQL_CODE_TYPE=’NATIVE’, because arithmetic operations on SIMPLE_INTEGER values are done directly in the hardware. When PLSQL_CODE_TYPE=’INTERPRETED’, the performance improvement is smaller.”

    So, it might be worthwile to do this test, too.

    Regards,
    Chris

  4. Hi.

    Yes. I know about SIMPLE_INTEGER. It is included in the example because originally the article contained a native compilation example, but it seemed rather pointless as it’s an unfair comparison (Native PL/SQL vs non-native Java).

    I’m still considering re-introducing it, but I would do a natively compiled PL/SQL vs a natively compiled Java, as that would be the only fair comparison. 🙂

    For the moment I’ve replaced SIMPLE_INTEGER with PLS_INTEGER so as not to confuse. Flip it back in if you want to try with native compilation. 🙂

    Cheers

    Tim…

  5. Hi,

    If you compare the exponentail function, you’ll see a big diffrence. In my environment, the java version is 5 times faster.

    create or replace function java_power(base number, exponent number) return number
    as language java
    name ‘java.lang.Math.pow(double, double) return double’;

    Guangjun

Comments are closed.