Reputation: 61
why below code is faster in php (oci) than c++ (occi)? For 50k rows php execute script in 30s. Program is executing in 5 min!
/* php - oci code */
$s = oci_parse($c, 'select "client" from test');
oci_execute($s, OCI_DEFAULT);
while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS))
{
$i++;
if ($i%1000 == 0) echo $i.' '.$row['client'].PHP_EOL;
}
/* c++ occi code */
string q("select client from test");
ora_stmt = ora_conn->createStatement (q);
ora_stmt->setPrefetchRowCount(1000); // THIS IS AN ANSWER
ResultSet *rset = ora_stmt->executeQuery();
while (rset->next ())
{
i++;
if (i%1000 == 0) cout << i << endl;
}
Is the any way to improve occi?
My answer:
ora_stmt->setPrefetchRowCount(1000);
Upvotes: 2
Views: 503
Reputation: 33655
A quick scan through the docs reveals what @unapersson above mentions could be correct, once you have constructed the Statement
, before executing the query, it may be worth playing around with the following settings:
setPrefetchMemorySize()
Set the amount of memory that will be used internally by OCCI to store data fetched during each round trip to the server.
setPrefetchRowCount()
Set the number of rows that will be fetched internally by OCCI during each round trip to the server.
I am under the impression that as it stands, each call to next()
could be triggering a round-trip to the server.
Upvotes: 4
Reputation: 208323
I don't know PHP, so I cannot really comment on that side. On the C++ side of things, you are flushing the output stream after each write, which could be a good amount of unneeded flushing. Remove the endl
and use '\n'
and test again:
if ( i % 1000 == 0 ) cout << i << '\n';
Upvotes: 1