Changes for more convenience

This commit is contained in:
Ralph Lange
2000-06-28 15:56:34 +00:00
parent 4f4d35a1d8
commit 1d1539d356

View File

@@ -1,5 +1,6 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include "osiTime.h"
#include "osiThread.h"
@@ -11,7 +12,7 @@ int osiTimeTest (void);
int osiTimeTest (void)
{
unsigned i;
unsigned i, error;
osiTime begin = osiTime::getCurrent();
const unsigned wasteTime = 100000u;
const int nTimes = 100;
@@ -22,7 +23,9 @@ int osiTimeTest (void)
unsigned long nanoSec;
double diff;
for(int iTimes=0; iTimes < nTimes; ++iTimes) {
printf ("osiTime Test (%3d loops)\n========================\n\n", nTimes);
for (int iTimes=0; iTimes < nTimes; ++iTimes) {
for (i=0; i<wasteTime; i++) {
osiTime tmp = osiTime::getCurrent();
}
@@ -30,56 +33,122 @@ int osiTimeTest (void)
osiTime end = osiTime::getCurrent();
diff = end - begin;
if(iTimes==0)
printf ("elapsed per call to osiTime::getCurrent() = %f\n",
diff/wasteTime);
stamp = begin;
ansiDate = begin;
ts = begin;
if (iTimes == 0) {
printf ("Elapsed time per call to osiTime::getCurrent() "
"(%d calls) = %f12 sec\n\n", wasteTime,
diff/wasteTime);
stamp = begin;
ansiDate = begin;
ts = begin;
printf ("The following should be your local time\ndisplayed using "
"four different internal representations:\n\n");
tsStampToTM (&tmAnsi, &nanoSec, &stamp);
tsStampToTM (&tmAnsi, &nanoSec, &stamp);
if(iTimes==0)
printf ("TS_STAMP = %s %lu nSec \n", asctime(&tmAnsi), nanoSec);
if(iTimes==0)
printf ("struct tm = %s %f\n", asctime(&ansiDate.ansi_tm),
ansiDate.nSec/(double)osiTime::nSecPerSec);
tmAnsi = *localtime (&ts.tv_sec);
if(iTimes==0)
ansiDate.nSec/(double)osiTime::nSecPerSec);
tmAnsi = *localtime (&ts.tv_sec);
printf ("struct timespec = %s %f\n", asctime(&ansiDate.ansi_tm),
ts.tv_nsec/(double)osiTime::nSecPerSec);
if(iTimes==0) begin.show (0);
ts.tv_nsec/(double)osiTime::nSecPerSec);
begin.show (0);
printf ("\n");
} else {
if (iTimes % 10 == 0)
printf (" ... now at loop %3d\n", iTimes);
}
osiTime copy = end;
if(!(copy==end)) printf("copy==end %d\n",iTimes);
if(!(copy<=end)) printf("copy<=end %d\n",iTimes);
if(!(copy>=end)) printf("copy>=end %d\n",iTimes);
if(!(end>begin)) printf("end>begin %d\n",iTimes);
if(!(end>=begin)) printf("end>=begin %d\n",iTimes);
if(!(begin<end)) printf("begin<end %d\n",iTimes);
if(!(begin<=end)) printf("begin<=end %d\n",iTimes);
if(!(begin!=end)) printf("begin!=end %d\n",iTimes);
if(!(end-begin==diff)) printf("end-begin==diff %d\n",iTimes);
error = 0;
if (!(copy==end)) {
printf ("Loop #%3d: Failed test copy==end\n",iTimes);
error = 1;
}
if (!(copy<=end)) {
printf ("Loop #%3d: Failed test copy<=end %d\n",iTimes);
error = 1;
}
if (!(copy>=end)) {
printf ("Loop #%3d: Failed test copy>=end %d\n",iTimes);
error = 1;
}
if (!(end>begin)) {
printf ("Loop #%3d: Failed test end>begin %d\n",iTimes);
error = 1;
}
if (!(end>=begin)) {
printf ("Loop #%3d: Failed test end>=begin %d\n",iTimes);
error = 1;
}
if (!(begin<end)) {
printf ("Loop #%3d: Failed test begin<end %d\n",iTimes);
error = 1;
}
if (!(begin<=end)) {
printf ("Loop #%3d: Failed test begin<=end %d\n",iTimes);
error = 1;
}
if (!(begin!=end)) {
printf ("Loop #%3d: Failed test begin!=end %d\n",iTimes);
error = 1;
}
if (!(end-begin==diff)) {
printf ("Loop #%3d: Failed test end-begin==diff %d\n",iTimes);
error = 1;
}
begin += diff;
if(!(begin==end)) printf("begin==end %d\n",iTimes);
if (!(begin==end) && (fabs(begin-end) > 1.0e-6)) {
printf ("Loop #%3d: Failed test (begin+=diff)==end by %12.9f\n",
iTimes, fabs(begin-end));
error = 1;
}
begin -= diff;
if(!(begin+diff==end)) printf("begin+diff==end %d\n",iTimes);
if (!(begin+diff==end) && (fabs(begin+diff-end) > 1.0e-6)) {
printf ("Loop #%3d: Failed test begin+diff==end\n",iTimes);
error = 1;
}
//
// test struct tm conversions
//
ansiDate = begin;
begin = ansiDate;
if(!(begin+diff==end)) printf("begin+diff==end %d\n",iTimes);
if (!(begin+diff==end) && (fabs(begin+diff-end) > 1.0e-6)) {
printf ("Loop #%3d: Failed test begin+diff==end "
"after tm conversions\n",iTimes);
error = 1;
}
//
// test struct timespec conversion
//
ts = begin;
begin = ts;
if(!(begin+diff==end)) printf("begin+diff==end %d\n",iTimes);
if (!(begin+diff==end) && (fabs(begin+diff-end) > 1.0e-6)) {
printf ("Loop #%3d: Failed test begin+diff==end "
"after timespec conversions\n",iTimes);
error = 1;
}
if (error) {
printf ("Loop #%3d: begin ", iTimes); begin.show(0);
printf ("Loop #%3d: end ", iTimes); end.show(0);
printf ("Loop #%3d: diff %12.9f\n\n", iTimes, diff);
}
}
return(0);
return 0;
}
/* **************************** Emacs Editing Sequences ***************** */
/* Local Variables: */
/* tab-width: 4 */
/* c-basic-offset: 4 */
/* c-comment-only-line-offset: 0 */
/* c-file-offsets: ((substatement-open . 0) (label . 0)) */
/* End: */