summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tests/speed.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tests/speed.cpp b/src/tests/speed.cpp
new file mode 100644
index 0000000..b8924d7
--- /dev/null
+++ b/src/tests/speed.cpp
@@ -0,0 +1,48 @@
1#include "bu/fstring.h"
2#include <sys/time.h>
3
4template<typename a>
5struct tstCopy
6{
7 tstCopy( const a &src ) :
8 src( src )
9 {
10 }
11
12 void operator()()
13 {
14 a tmp = src;
15 }
16
17 a src;
18};
19
20template<typename f>
21double runTest( f fnc )
22{
23 struct timeval tStart, tEnd;
24 int j = 0;
25 gettimeofday( &tStart, NULL );
26 for(; j < 500000; j++ )
27 fnc();
28 gettimeofday( &tEnd, NULL );
29
30 return (double)(tEnd.tv_sec-tStart.tv_sec)+
31 (double)(tEnd.tv_usec-tStart.tv_usec)/1000000.0;
32}
33
34template<typename tst>
35void fullTest( tst t )
36{
37 double dTotal;
38 int iCount = 10;
39 for( int j = 0; j < iCount; j++ )
40 dTotal += runTest( t );
41 printf("Average time: %f\n", dTotal/iCount );
42}
43
44int main()
45{
46 fullTest( tstCopy<Bu::FString>("This is a test string.") );
47}
48