From 42f4f849c683bc30404727f4dccc9d3cfd030adf Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 14 Aug 2009 12:48:21 +0000 Subject: A good start on a speed test framework. --- src/tests/speed.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/tests/speed.cpp 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 @@ +#include "bu/fstring.h" +#include + +template +struct tstCopy +{ + tstCopy( const a &src ) : + src( src ) + { + } + + void operator()() + { + a tmp = src; + } + + a src; +}; + +template +double runTest( f fnc ) +{ + struct timeval tStart, tEnd; + int j = 0; + gettimeofday( &tStart, NULL ); + for(; j < 500000; j++ ) + fnc(); + gettimeofday( &tEnd, NULL ); + + return (double)(tEnd.tv_sec-tStart.tv_sec)+ + (double)(tEnd.tv_usec-tStart.tv_usec)/1000000.0; +} + +template +void fullTest( tst t ) +{ + double dTotal; + int iCount = 10; + for( int j = 0; j < iCount; j++ ) + dTotal += runTest( t ); + printf("Average time: %f\n", dTotal/iCount ); +} + +int main() +{ + fullTest( tstCopy("This is a test string.") ); +} + -- cgit v1.2.3