summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-09-18 09:42:16 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-09-27 18:09:18 +0100
commitc058510595812af9254c7e95ca97e3a84c8d354d (patch)
treed5bf2a8ad6ff8d61a5560f7b1652e86c89b0200d /dbaccess
parent7c87a5383ae03df0f9ad0e39cfbd6f83645a659a (diff)
Refactor performance test.
This is to allow for comparing the use of Prepared/Normal statements. Change-Id: I6e120892f1c66f8b1c59bda309e88b2b7f39d230
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/qa/unit/embeddeddb_performancetest.cxx187
1 files changed, 99 insertions, 88 deletions
diff --git a/dbaccess/qa/unit/embeddeddb_performancetest.cxx b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
index 7d511029a59b..7832cfc19b4f 100644
--- a/dbaccess/qa/unit/embeddeddb_performancetest.cxx
+++ b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
@@ -85,6 +85,17 @@ private:
void doPerformanceTestOnODB(const OUString& rFileName, const OUString& rDBName);
+ void setupTestTable(uno::Reference< XConnection >& xConnection);
+
+ // Individual Tests
+ void performPreparedStatementInsertTest(
+ uno::Reference< XConnection >& xConnection,
+ const OUString& rDBName);
+ void performReadTest(
+ uno::Reference< XConnection >& xConnection,
+ const OUString& rDBName);
+
+ // Perform all tests on a given DB.
void testFirebird();
void testHSQLDB();
@@ -164,107 +175,107 @@ void EmbeddedDBPerformanceTest::doPerformanceTestOnODB(
uno::Reference< XConnection > xConnection =
getConnectionForDocument(xDocument);
- // Create Table
+ setupTestTable(xConnection);
+
+ performPreparedStatementInsertTest(xConnection, rDBName);
+ performReadTest(xConnection, rDBName);
+
+// xConnection.dispose();
+
+}
+
+void EmbeddedDBPerformanceTest::setupTestTable(
+ uno::Reference< XConnection >& xConnection)
+{
+ uno::Reference< XStatement > xStatement = xConnection->createStatement();
+
+ // Although not strictly necessary we use quoted identifiers to reflect
+ // the fact that Base always uses quoted identifiers.
+ xStatement->execute(
+ "CREATE TABLE \"PFTESTTABLE\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY "
+ ", \"STRINGCOLUMNA\" VARCHAR (50) "
+ ")");
+
+ xConnection->commit();
+}
+
+void EmbeddedDBPerformanceTest::performPreparedStatementInsertTest(
+ uno::Reference< XConnection >& xConnection,
+ const OUString& rDBName)
+{
+ uno::Reference< XPreparedStatement > xPreparedStatement =
+ xConnection->prepareStatement(
+ "INSERT INTO \"PFTESTTABLE\" ( \"ID\", "
+ "\"STRINGCOLUMNA\" "
+ ") VALUES ( ?, ? )"
+ );
+
+ uno::Reference< XParameters > xParameters(xPreparedStatement, UNO_QUERY_THROW);
+
+ ::boost::scoped_ptr< SvFileStream > pFile(new SvFileStream(
+ getSrcRootURL() + our_sFilePath + "wordlist",
+ STREAM_READ));
+
+ if (!pFile)
{
- uno::Reference< XStatement > xStatement = xConnection->createStatement();
- CPPUNIT_ASSERT(xStatement.is());
-
- // Although not strictly necessary we use quoted identifiers to reflect
- // the fact that Base always uses quoted identifiers.
- xStatement->execute(
- "CREATE TABLE \"PFTESTTABLE\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY "
- ", \"STRINGCOLUMNA\" VARCHAR (50) "
-// ", \"STRINGCOLUMNB\" VARCHAR (50) "
-// ", \"STRINGCOLUMNC\" VARCHAR (50) "
-// ", \"STRINGCOLUMND\" VARCHAR (50) "
- ")");
- xConnection->commit();
+ fprintf(stderr, "Please ensure the wordlist is present\n");
+ CPPUNIT_ASSERT(false);
}
- // Writing test
+ OUString aWord;
+ sal_Int32 aID = 0;
+
+ TimeValue aStart, aMiddle, aEnd;
+ osl_getSystemTime(&aStart);
+
+ while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8))
{
- uno::Reference< XPreparedStatement > xPreparedStatement =
- xConnection->prepareStatement(
- "INSERT INTO \"PFTESTTABLE\" ( \"ID\", "
- "\"STRINGCOLUMNA\" "
-// ", \"STRINGCOLUMNB\" "
-// ", \"STRINGCOLUMNC\" "
-// ", \"STRINGCOLUMND\" "
- ") VALUES ( ?, ?"
-// ", ?, ?, ? "
- ")");
-
- uno::Reference< XParameters > xParameters(xPreparedStatement, UNO_QUERY_THROW);
-
- ::boost::scoped_ptr< SvFileStream > pFile(new SvFileStream(
- getSrcRootURL() + our_sFilePath + "wordlist",
- STREAM_READ));
-
- if (!pFile)
- {
- fprintf(stderr, "Please ensure the wordlist is present\n");
- CPPUNIT_ASSERT(false);
- }
-
- OUString aWord;
- sal_Int32 aID = 0;
-
- TimeValue aStart, aMiddle, aEnd;
- osl_getSystemTime(&aStart);
-
- while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8))
- {
- xParameters->setInt(1, aID++);
- xParameters->setString(2, aWord);
-// xParameters->setString(3, aWord);
-// xParameters->setString(4, aWord);
-// xParameters->setString(5, aWord);
- xPreparedStatement->execute();
- }
- osl_getSystemTime(&aMiddle);
- xConnection->commit();
- osl_getSystemTime(&aEnd);
-
-
- TimeValue aTimeInsert, aTimeCommit, aTimeTotal;
- getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
- getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
- getTimeDifference(&aStart, &aEnd, &aTimeTotal);
- m_aOutputBuffer.append("Write to: " + rDBName + "\n");
- printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
-
- pFile->Close();
+ xParameters->setInt(1, aID++);
+ xParameters->setString(2, aWord);
+ xPreparedStatement->execute();
}
+ osl_getSystemTime(&aMiddle);
+ xConnection->commit();
+ osl_getSystemTime(&aEnd);
- // Read test
- {
- uno::Reference< XStatement > xStatement = xConnection->createStatement();
- TimeValue aStart, aMiddle, aEnd;
- osl_getSystemTime(&aStart);
+ TimeValue aTimeInsert, aTimeCommit, aTimeTotal;
+ getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
+ getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
+ getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+ m_aOutputBuffer.append("PreparedStatement Insert: " + rDBName + "\n");
+ printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
- uno::Reference< XResultSet > xResults = xStatement->executeQuery("SELECT * FROM PFTESTTABLE");
+ pFile->Close();
+}
+
+void EmbeddedDBPerformanceTest::performReadTest(
+ uno::Reference< XConnection >& xConnection,
+ const OUString& rDBName)
+{
+ uno::Reference< XStatement > xStatement = xConnection->createStatement();
+
+ TimeValue aStart, aMiddle, aEnd;
+ osl_getSystemTime(&aStart);
- osl_getSystemTime(&aMiddle);
+ uno::Reference< XResultSet > xResults = xStatement->executeQuery("SELECT * FROM PFTESTTABLE");
- uno::Reference< XRow > xRow(xResults, UNO_QUERY_THROW);
+ osl_getSystemTime(&aMiddle);
- while (xResults->next())
- {
- xRow->getString(2);
-// xRow->getString(3);
-// xRow->getString(4);
-// xRow->getString(5);
- }
- osl_getSystemTime(&aEnd);
+ uno::Reference< XRow > xRow(xResults, UNO_QUERY_THROW);
- TimeValue aTimeSelect, aTimeIterate, aTimeTotal;
- getTimeDifference(&aStart, &aMiddle, &aTimeSelect);
- getTimeDifference(&aMiddle, &aEnd, &aTimeIterate);
- getTimeDifference(&aStart, &aEnd, &aTimeTotal);
- m_aOutputBuffer.append("Read from: " + rDBName + "\n");
- printTimes(&aTimeSelect, &aTimeIterate, &aTimeTotal);
+ while (xResults->next())
+ {
+ xRow->getString(2);
}
+ osl_getSystemTime(&aEnd);
+
+ TimeValue aTimeSelect, aTimeIterate, aTimeTotal;
+ getTimeDifference(&aStart, &aMiddle, &aTimeSelect);
+ getTimeDifference(&aMiddle, &aEnd, &aTimeIterate);
+ getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+ m_aOutputBuffer.append("Read from: " + rDBName + "\n");
+ printTimes(&aTimeSelect, &aTimeIterate, &aTimeTotal);
}
CPPUNIT_TEST_SUITE_REGISTRATION(EmbeddedDBPerformanceTest);