summaryrefslogtreecommitdiff
path: root/ACEXML/tests
diff options
context:
space:
mode:
authormichel_j <michel_j@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2005-05-23 18:10:38 +0000
committermichel_j <michel_j@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2005-05-23 18:10:38 +0000
commit3faf4be34859ecb3e7e83ee357760caba0696511 (patch)
treeee7809b50251dc9f463337e695767abdfa023118 /ACEXML/tests
parent46cffda57a5a0a26594b2eb3a5b3a565c094846f (diff)
downloadATCD-3faf4be34859ecb3e7e83ee357760caba0696511.tar.gz
ChangeLogTag: Mon May 23 13:02:25 2005 Justin Michel <michel_j@ociweb.com>
Diffstat (limited to 'ACEXML/tests')
-rw-r--r--ACEXML/tests/util/test.cpp110
-rw-r--r--ACEXML/tests/util/util.mpc3
2 files changed, 113 insertions, 0 deletions
diff --git a/ACEXML/tests/util/test.cpp b/ACEXML/tests/util/test.cpp
new file mode 100644
index 00000000000..8ed59accc59
--- /dev/null
+++ b/ACEXML/tests/util/test.cpp
@@ -0,0 +1,110 @@
+// $Id$
+// A simple test for performance of the ACEXML_escape_string() function
+
+#include "ACEXML/common/XML_Util.h"
+
+#include "ace/OS_main.h"
+#include "ace/Time_Value.h"
+#include "ace/OS_NS_sys_time.h"
+#include "ace/Log_Msg.h"
+
+const int MAX_ITERATIONS = 100 * 1000;
+const int NUM_TEST_STRS = 6;
+
+static bool is_escaped(const ACEXML_String& s)
+{
+ if (s[0] != ACE_TEXT('&'))
+ return false;
+ if (s[s.length() - 1] != ACE_TEXT(';'))
+ return false;
+ return true;
+}
+
+static int run_tests(ACEXML_String test_strings[NUM_TEST_STRS], int iterations)
+{
+ // Test 1 - Escape the strings using a new temporary string each iteration.
+ ACE_Time_Value start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ ACEXML_String tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test1 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+
+ // Test 2 - Escape the strings using a shared temporary string. This shouldn't
+ // be any faster than Test 1 as long as the compiler has return value optimization.
+ ACEXML_String tmp;
+ start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test2 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+
+ // Test 3 - Escape the strings using a shared temporary string. This time, we use
+ // the alternate form of ACEXML_escape_string() so that our temporary buffer is reused.
+ tmp.clear(1);
+ start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test3 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+
+ // Test 4 - Same as Test 3, except that the tmp buffer shouldn't have to resize.
+ start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test4 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+ return 0;
+}
+
+int ACE_TMAIN (int, ACE_TCHAR *[])
+{
+ ACEXML_String test_strings[NUM_TEST_STRS] = {
+ ACE_TEXT("\"xxxxx\"xxxxxxxx xx\"xxxxxx xxxxxx\"xxxxxxxxxx xxxxxxxx\"xxxxxx\""),
+ ACE_TEXT("'xxxxx\'xxxxxxxx' xxxxxxxx xx'xxxxxxxx'xxxxxx xxxxxxx'xxxxxxx'"),
+ ACE_TEXT("&xxxx&xxxxxxxxx &xxxxxxxx xxxxx&xxxxxxxxxxx xxxx&xxxxxxxxxx&"),
+ ACE_TEXT(">xx>xxxxxxxxxxx >xxxxxxxx xxxxx>xxxxxxxxxxx xxxxx>xxxxxxxxx>"),
+ ACE_TEXT("<xxxxx<xxxxxxxx xxxxxxxx <xxxxxxxxxxxxxxx<x xxxxxxxxxxxxxx<"),
+ ACE_TEXT("&xxxx\"xxxxxxx&xx xxx'xxxxx xx<xxxxxxx>xxxxxxx xx\"xxxxxxxxxxxx>"),
+ };
+
+ if (run_tests(test_strings, MAX_ITERATIONS) != 0)
+ return 1;
+
+ ACE_DEBUG((LM_DEBUG, "Rerun tests with larger strings\n"));
+ for (int i = 0; i < NUM_TEST_STRS; ++i)
+ {
+ for (int j = 0; j < 5; ++j)
+ {
+ test_strings[i] += test_strings[i];
+ }
+ }
+
+ if (run_tests(test_strings, MAX_ITERATIONS / 10) != 0)
+ return 1;
+
+ return 0;
+}
diff --git a/ACEXML/tests/util/util.mpc b/ACEXML/tests/util/util.mpc
new file mode 100644
index 00000000000..892350c7bc8
--- /dev/null
+++ b/ACEXML/tests/util/util.mpc
@@ -0,0 +1,3 @@
+project: aceexe, acexml {
+ exename = test
+}