[sword-svn] r1782 - trunk/tests
scribe at crosswire.org
scribe at crosswire.org
Fri Apr 29 17:07:51 MST 2005
Author: scribe
Date: 2005-04-29 17:07:50 -0700 (Fri, 29 Apr 2005)
New Revision: 1782
Modified:
trunk/tests/swbuftest.cpp
Log:
Modified: trunk/tests/swbuftest.cpp
===================================================================
--- trunk/tests/swbuftest.cpp 2005-04-23 21:03:41 UTC (rev 1781)
+++ trunk/tests/swbuftest.cpp 2005-04-30 00:07:50 UTC (rev 1782)
@@ -1,103 +1,108 @@
#include <iostream>
-#include <swbuf.h>
-using namespace sword;
-using namespace std;
-#define BASEI 32000000L
+#define BASEI 320000000L
-SWBuf speed;
+//#include <swbuf.h>
+//typedef sword::SWBuf StringType;
+#include <string>
+typedef std::string StringType;
+
+using std::cout;
+using std::cerr;
+
+
void appendChTest() {
- cerr << "\nappend ch test -------\n";
+ cerr << "\nSTART: append ch test -------\n";
cerr.flush();
+ StringType s;
for (unsigned long i = 0; i < BASEI+14; i++) {
- speed += (char) (i%125)+1;
+ s += (char) (i%125)+1;
}
- speed.resize(BASEI/100L);
- cout << "\nappend ch test -------\n";
-// cout << speed << "\n";
+ cerr << "\nEND: append ch test -------\n";
+ cerr.flush();
}
void appendStringTest() {
- // append test
- cerr << "\nappend string test -------\n";
+ cerr << "\nSTART: append string test -------\n";
cerr.flush();
+ StringType s;
unsigned long iterations = BASEI/2L;
for (unsigned long i = 0; i < iterations; i++) {
- speed.append("this is a test", 3);
- if (!(i%3))speed.append("test");
+ s.append("this is a test", 3);
+ if (!(i%3))s.append("test");
}
- cout << "\nappend string test -------\n";
- speed = SWBuf(speed.c_str() + iterations);
- speed.resize(BASEI/100L);
-// cout << speed << "\n";
+ cerr << "\nEND: append string test -------\n";
+ cerr.flush();
}
void subscriptTest() {
- // subscript access test;
- cerr << "\nsubscript access test -------\n";
+ cerr << "\nSTART: subscript access test -------\n";
cerr.flush();
- for (int j = 0; j < 200; j++) {
- for (unsigned long i = speed.length()-1; i; i--) {
- speed[i] = (char) (i%40)+65;
+ StringType s;
+ for (int j = 0; j < 100; j++) {
+ s += "0123456789";
+ }
+ for (int j = 0; j < BASEI/500; j++) {
+ for (unsigned long i = s.length()-1; i; i--) {
+ s[i] = (char) (i%40)+65;
}
}
- cout << "\nsubscript access test -------\n";
-// cout << speed << "\n";
+ cerr << "\nEND: subscript access test -------\n";
+ cerr.flush();
}
void ctorAssignTest() {
- // construct and assign test
- cerr << "\nconstructor and assign test -------\n";
+ cerr << "\nSTART: constructor and assign test -------\n";
cerr.flush();
- for (unsigned long i = (BASEI/8000L); i; i--) {
- SWBuf speedl;
- speedl = speed;
+ StringType s;
+ for (int j = 0; j < 100; j++) {
+ s += "0123456789";
}
- cout << "\nconstructor and assign test -------\n";
- SWBuf speedl;
- speedl = speed;
-// cout << speedl << "\n";
+ for (unsigned long i = (BASEI/4); i; i--) {
+ StringType s2;
+ s2 = s;
+ s2.c_str(); // keep us from being optimized out
+ }
+ cerr << "\nEND: constructor and assign test -------\n";
+ cerr.flush();
}
void compareTest() {
- // compare test
- cerr << "\ncompare test -------\n";
+ cerr << "\nSTART: compare test -------\n";
cerr.flush();
- SWBuf first = "firsttest";
- SWBuf second = "first2test";
- cout << "\ncompare test -------\n";
- for (unsigned long i = BASEI/5; i; i--) {
+ StringType first = "firsttestAfirst";
+ StringType second = "firsttestBsecond";
+ for (unsigned long i = BASEI/2; i; i--) {
if (first != second)
- if (first >= second)
- if (first < second);
- else if (!(BASEI%1000)) cout << "g";
+ if (first <= second)
+ if (first > second);
+ else if (!(BASEI%10000)) first[0] = 'f'; // keep us from being optimized out
}
+ cerr << "\nEND: compare test -------\n";
+ cerr.flush();
}
void insertStringTest() {
- // insert test
- cerr << "\ninsert string test -------\n";
+ cerr << "\nSTART: insert string test -------\n";
cerr.flush();
-
- speed = "Start\nend";
- for (int i = 0; i < 1000; ++i) {
- speed.insert(6, "text ->this part should not appear :)", 5);
- speed.insert(6, SWBuf("text ->this part should not appear :)"), 5);
- //if (!(i%3))speed.append("test");
+ StringType s;
+ StringType sub = "text ->this part should not appear :)";
+ for (int j = 0; j < BASEI/10000; j++) {
+ s = "Start end";
+ for (int i = 0; i < 1000; i++) {
+ s.insert(s.length()/2, sub, 0, 5);
+ }
}
- cout << "\ninsert string test -------\n";
-
- //speed = SWBuf(speed.c_str() + iterations);
- //speed.resize(BASEI/100L);
-// cout << speed << "\n";
+ cerr << "\nEND: insert string test -------\n";
+ cerr.flush();
}
int main(int argc, char **argv) {
- SWBuf x;
+ StringType x;
cout << "x should be (): (" << x << ")\n";
cout << "size should be 0: " << x.size() << "\n";
x = "hello";
@@ -109,20 +114,20 @@
x[7] = 'u';
cout << "x[7] should be 'u': '" << x[7] << "'\n";
cout << "x should be (hello wurld): (" << x << ")\n";
- SWBuf y = x + " " + x;
+ StringType y = x + " " + x;
cout << "should be (hello wurld hello wurld): (" << y << ")\n";
// y.appendFormatted(" from %d %s running %02.05f miles", 4, "dogs", 1.9f);
- cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles): (" << y << ")\n";
- y += '!';
- cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles!): (" << y << ")\n";
- y.append(y.c_str(),5);
- cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles!hello): (" << y << ")\n";
+// cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles): (" << y << ")\n";
+// y += '!';
+// cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles!): (" << y << ")\n";
+// y.append(y.c_str(),5);
+// cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles!hello): (" << y << ")\n";
- insertStringTest();
appendChTest();
appendStringTest();
subscriptTest();
ctorAssignTest();
-// compareTest();
+ compareTest();
+ insertStringTest();
}
More information about the sword-cvs
mailing list