summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-05-17 21:45:50 +0000
committerMike Buland <eichlan@xagasoft.com>2007-05-17 21:45:50 +0000
commit326125aee0b8cd807a6a1d158398078ff6bfb1e1 (patch)
tree01ce1ba9d6b551ac621c73276eeb23268d315f43
parente0e7932a122614a0ff566fbfd8de5776de8b9f6d (diff)
downloadlibbu++-326125aee0b8cd807a6a1d158398078ff6bfb1e1.tar.gz
libbu++-326125aee0b8cd807a6a1d158398078ff6bfb1e1.tar.bz2
libbu++-326125aee0b8cd807a6a1d158398078ff6bfb1e1.tar.xz
libbu++-326125aee0b8cd807a6a1d158398078ff6bfb1e1.zip
As evidenced by my latest test, the Bu::FString copy is actually slower than
the std::string copy by a rather large margin. This seems very odd, so I'm going to do a few tests, the first one is stripping out the FString shared pointer stuff and seeing if that makes an appreciable difference.
-rw-r--r--build.conf3
-rw-r--r--src/fstring.h4
-rw-r--r--src/old/tests/fstring.cpp48
-rw-r--r--src/tests/fstring.cpp130
4 files changed, 136 insertions, 49 deletions
diff --git a/build.conf b/build.conf
index c289205..35738e3 100644
--- a/build.conf
+++ b/build.conf
@@ -6,6 +6,9 @@ default action: check group "lnhdrs", check "libbu++.a"
6 6
7set "CXXFLAGS" += "-ggdb -Wall" 7set "CXXFLAGS" += "-ggdb -Wall"
8 8
9#set "CXXFLAGS" += "-pg"
10#set "LDFLAGS" += "-pg"
11
9filesIn("src") filter regexp("^src/(.*)\\.h$", "src/bu/{re:1}.h"): 12filesIn("src") filter regexp("^src/(.*)\\.h$", "src/bu/{re:1}.h"):
10 rule "hln", 13 rule "hln",
11 group "lnhdrs", 14 group "lnhdrs",
diff --git a/src/fstring.h b/src/fstring.h
index f738f63..43033b8 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -7,6 +7,8 @@
7#include "archive.h" 7#include "archive.h"
8#include "hash.h" 8#include "hash.h"
9 9
10#define min( a, b ) ((a<b)?(a):(b))
11
10namespace Bu 12namespace Bu
11{ 13{
12 template< typename chr > 14 template< typename chr >
@@ -131,7 +133,7 @@ namespace Bu
131 appendChunk( pNew ); 133 appendChunk( pNew );
132 } 134 }
133 135
134 void append( const chr cData ) 136 void append( const chr &cData )
135 { 137 {
136 append( &cData, 1 ); 138 append( &cData, 1 );
137 } 139 }
diff --git a/src/old/tests/fstring.cpp b/src/old/tests/fstring.cpp
deleted file mode 100644
index 271738c..0000000
--- a/src/old/tests/fstring.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
1#include "hash.h"
2#include "fstring.h"
3
4FString genThing()
5{
6 FString bob;
7 bob.append("ab ");
8 bob += "cd ";
9 bob += "efg";
10
11 printf("---bob------\n%08X: %s\n", (unsigned int)bob.c_str(), bob.c_str() );
12 return bob;
13}
14
15void thing( FString str )
16{
17 printf("Hey: %s\n", str.c_str() );
18}
19
20#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() );
21int main( int argc, char *argv )
22{
23 FString str("th");
24
25 str.prepend("Hello ");
26 str.append("ere.");
27
28 FString str2( str );
29 pem;
30 str += " What's up?";
31 pem;
32 str2 += " How are you?";
33 pem;
34 str = str2;
35 pem;
36
37 str2 = genThing();
38 pem;
39
40 str = str2;
41 pem;
42
43 thing( str2 );
44 thing("test.");
45
46 printf("%d == %d\n", __calcHashCode( str ), __calcHashCode( str.c_str() ) );
47}
48
diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp
new file mode 100644
index 0000000..d600be6
--- /dev/null
+++ b/src/tests/fstring.cpp
@@ -0,0 +1,130 @@
1#include "bu/hash.h"
2#include "bu/fstring.h"
3#include <sys/time.h>
4#include <string>
5
6inline double getTime()
7{
8 struct timeval tv;
9 gettimeofday( &tv, NULL );
10 return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0);
11}
12
13Bu::FString genThing()
14{
15 Bu::FString bob;
16 bob.append("ab ");
17 bob += "cd ";
18 bob += "efg";
19
20 printf("---bob------\n%08X: %s\n", (unsigned int)bob.c_str(), bob.c_str() );
21 return bob;
22}
23
24void thing( Bu::FString str )
25{
26 printf("Hey: %s\n", str.c_str() );
27}
28
29void copyfunc( std::string temp )
30{
31 temp += "Hi";
32}
33
34void copyfunc( Bu::FString temp )
35{
36 temp += "Hi";
37}
38
39void doTimings()
40{
41 Bu::FString fs1, fs2;
42 std::string ss1, ss2;
43 double dStart, dEnd, tfs1, tfs2, tfs3, tss1, tss2, tss3;
44 int nChars = 500000, nChunks=5000, nCopies=5000000, nChunkSize=1024*4;
45 char *buf = new char[nChunkSize];
46 memset( buf, '!', nChunkSize );
47
48 printf("Timing Bu::FString single chars...\n");
49 dStart = getTime();
50 for( int j = 0; j < nChars; j++ ) fs1 += (char)('a'+(j%26));
51 fs1.getStr();
52 dEnd = getTime();
53 tfs1 = dEnd-dStart;
54
55 printf("Timing std::string single chars...\n");
56 dStart = getTime();
57 for( int j = 0; j < nChars; j++ ) ss1 += (char)('a'+(j%26));
58 ss1.c_str();
59 dEnd = getTime();
60 tss1 = dEnd-dStart;
61
62 printf("Timing Bu::FString %d char chunks...\n", nChunkSize);
63 dStart = getTime();
64 for( int j = 0; j < nChunks; j++ ) fs2.append(buf, nChunkSize);
65 fs2.getStr();
66 dEnd = getTime();
67 tfs2 = dEnd-dStart;
68
69 printf("Timing std::string %d char chunks...\n", nChunkSize);
70 dStart = getTime();
71 for( int j = 0; j < nChunks; j++ ) ss2.append(buf, nChunkSize);
72 ss2.c_str();
73 dEnd = getTime();
74 tss2 = dEnd-dStart;
75
76 fs2 = "Hello there.";
77 ss2 = "Hello there.";
78 printf("Timing Bu::FString copies...\n");
79 dStart = getTime();
80 for( int j = 0; j < nCopies; j++ ) Bu::FString stmp = fs2;
81 dEnd = getTime();
82 tfs3 = dEnd-dStart;
83
84 printf("Timing std::string copies...\n");
85 dStart = getTime();
86 for( int j = 0; j < nCopies; j++ ) std::string stpm = ss2;
87 dEnd = getTime();
88 tss3 = dEnd-dStart;
89
90 printf(
91 "Results: singles: chunks: copies:\n"
92 "Bu::FString %10.2f/s %10.2f/s %10.2f/s\n"
93 "std::string %10.2f/s %10.2f/s %10.2f/s\n",
94 nChars/tfs1, nChunks/tfs2, nCopies/tfs3,
95 nChars/tss1, nChunks/tss2, nCopies/tss3 );
96
97 delete[] buf;
98}
99
100#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() );
101int main( int argc, char *argv )
102{
103 Bu::FString str("th");
104
105 str.prepend("Hello ");
106 str.append("ere.");
107
108 Bu::FString str2( str );
109 pem;
110 str += " What's up?";
111 pem;
112 str2 += " How are you?";
113 pem;
114 str = str2;
115 pem;
116
117 str2 = genThing();
118 pem;
119
120 str = str2;
121 pem;
122
123 thing( str2 );
124 thing("test.");
125
126 printf("%d == %d\n", Bu::__calcHashCode( str ), Bu::__calcHashCode( str.c_str() ) );
127
128 doTimings();
129}
130