add speed comparison
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@375 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
7eb9f2e6ae
commit
6b5d0e2629
1 changed files with 125 additions and 112 deletions
|
@ -14,6 +14,8 @@
|
|||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
#include "../SmallObj/timer.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <class Integral1, class Integral2>
|
||||
|
@ -90,39 +92,49 @@ void TestCase2(const string& fmt, T value, U value2)
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc == 3)
|
||||
if (argc == 2)
|
||||
{
|
||||
// test speed
|
||||
int i = atoi(argv[2]);
|
||||
switch (argv[1][0])
|
||||
{
|
||||
case 'p':
|
||||
for (; i > 0; --i)
|
||||
{
|
||||
printf("Hey, %u frobnicators and %u twiddlicators\n",
|
||||
i, i);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
for (; i > 0; --i)
|
||||
{
|
||||
cout << "Hey, " << i << " frobnicators and " << i <<
|
||||
" twiddlicators\n";
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
for (; i > 0; --i)
|
||||
{
|
||||
Printf("Hey, %u frobnicators and %u twiddlicators\n")
|
||||
(i)(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Timer t;
|
||||
|
||||
int loop = atoi(argv[1]);
|
||||
|
||||
if(loop < 100)
|
||||
loop = 100;
|
||||
|
||||
t.start();
|
||||
for (int i=loop; i > 0; --i)
|
||||
printf("Hey, %u frobnicators and %u twiddlicators\n",i, i);
|
||||
t.stop();
|
||||
t.t100 = t.t();
|
||||
int t_printf = t.t();
|
||||
|
||||
|
||||
t.start();
|
||||
for (int i=loop; i > 0; --i)
|
||||
Printf("Hey, %u frobnicators and %u twiddlicators\n")(i)(i);
|
||||
t.stop();
|
||||
int t_Printf = t.t();
|
||||
|
||||
|
||||
t.start();
|
||||
for (int i=loop; i > 0; --i)
|
||||
cout << "Hey, " << i << " frobnicators and " << i <<" twiddlicators\n";
|
||||
t.stop();
|
||||
int t_cout = t.t();
|
||||
|
||||
|
||||
Printf("\n\nElapsed time for %i outputs\n\n")(loop);
|
||||
t.print(t_printf,"printf : ");
|
||||
t.print(t_Printf,"Printf : ");
|
||||
t.print(t_cout, "std::cout: ");
|
||||
}
|
||||
else
|
||||
{
|
||||
//srand(time(0));
|
||||
srand(0);
|
||||
printf("\nNumber of tests:\n");
|
||||
for (unsigned i = 0; ; ++i)
|
||||
{
|
||||
printf("%u\r", i);
|
||||
|
@ -211,3 +223,4 @@ int main(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue