Hello
I have an stored procedure to write and I prefer Java personally, but thought that PL/SQL might be a better choice because of performance. I'm not an expert but doesn't it essentially run in the Oracle process as opposed to Java, which runs in it's own JVM?
I was surprised when I did a performance test and found that Java was twice as fast. The test is simply to read 1 million values from a table and return the sum (using a loop). Both are implemented as stored procedures. PL/SQL takes 20 seconds, and Java 12 seconds. It seems pretty reproducible. Nothing else goes on in the code - I have included it at the bottom of the post for reference.
Is this to be expected?
Thanks for any input.
Mark
Mark![[openup] [openup] [openup]](/data/assets/smilies/openup.gif)
I have an stored procedure to write and I prefer Java personally, but thought that PL/SQL might be a better choice because of performance. I'm not an expert but doesn't it essentially run in the Oracle process as opposed to Java, which runs in it's own JVM?
I was surprised when I did a performance test and found that Java was twice as fast. The test is simply to read 1 million values from a table and return the sum (using a loop). Both are implemented as stored procedures. PL/SQL takes 20 seconds, and Java 12 seconds. It seems pretty reproducible. Nothing else goes on in the code - I have included it at the bottom of the post for reference.
Is this to be expected?
Thanks for any input.
Mark
Code:
CREATE OR REPLACE procedure TestSpeedPLSQL is
cursor LoopCursor is select t.INT_VALUE from test_speed t;
lRunningTotal number;
lThisValue number;
startTime date;
begin
startTime := sysdate;
lRunningTotal := 0;
open LoopCursor;
loop
fetch LoopCursor into lThisValue;
exit when LoopCursor%NotFound;
lRunningTotal := lRunningTotal + lThisValue;
end loop;
close LoopCursor;
dbms_output.put_line(lRunningTotal);
dbms_output.put_line((sysdate - startTime) * 86400);
end;
/
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
public class TestOraJ2
{
public static double Total(int iValue)
{
//loop thru and sum values from test table
double iThisValue;
double iRunningTotal = 0;
System.out.println("This is from Java");
Connection conn = null;
try{
conn = new OracleDriver().defaultConnection();
String SQL = "Select Int_Value from Test_Speed";
Statement s = conn.createStatement();
ResultSet r = s.executeQuery(SQL);
while (r.next())
{
iThisValue = r.getDouble(1);
iRunningTotal += iThisValue;
}
r.close();
s.close();
}
catch (SQLException e)
{
e.printStackTrace(System.err);
return -1;
}
catch (Exception e)
{
e.printStackTrace(System.err);
return -2;
}
finally
{
try{conn.close();} catch(Exception e) {}
}
return iRunningTotal;
}
}
Mark
![[openup] [openup] [openup]](/data/assets/smilies/openup.gif)