blob: 5b26dd3635a6c2d393681982ea95299d12ab391d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include "bu/fstring.h"
#include <sys/time.h>
template<typename a>
struct tstCopy
{
tstCopy( const a &src ) :
src( src )
{
}
void operator()()
{
a tmp = src;
}
a src;
};
template<typename f>
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<typename tst>
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()
{
Bu::FString str;
for( int j = 0; j < 500; j++ )
str.append("Hey, this is a test string. It will be reapeated many, many times. How's that?");
fullTest( tstCopy<Bu::FString>( str ) );
}
|