aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-08-14 12:48:21 +0000
committerMike Buland <eichlan@xagasoft.com>2009-08-14 12:48:21 +0000
commit42f4f849c683bc30404727f4dccc9d3cfd030adf (patch)
treedfe42973e52aec363fcb97fc1c8a003c4a1fdef6 /src/tests
parent3d5c548d630f8b6c86a250e1b7358824557ef01f (diff)
downloadlibbu++-42f4f849c683bc30404727f4dccc9d3cfd030adf.tar.gz
libbu++-42f4f849c683bc30404727f4dccc9d3cfd030adf.tar.bz2
libbu++-42f4f849c683bc30404727f4dccc9d3cfd030adf.tar.xz
libbu++-42f4f849c683bc30404727f4dccc9d3cfd030adf.zip
A good start on a speed test framework.
Diffstat (limited to '')
-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