move epoch_usec() to test.c
This commit is contained in:
parent
f7d3c2bfa1
commit
abe8d26246
30
demos/test.c
30
demos/test.c
@ -32,6 +32,36 @@ static const struct {
|
|||||||
LTC_TEST_FN(multi_test),
|
LTC_TEST_FN(multi_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h> /* GetSystemTimeAsFileTime */
|
||||||
|
#else
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* microseconds since 1970 (UNIX epoch) */
|
||||||
|
static ulong64 epoch_usec(void)
|
||||||
|
{
|
||||||
|
#if defined(LTC_NO_TEST_TIMING)
|
||||||
|
return 0;
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
FILETIME CurrentTime;
|
||||||
|
ulong64 cur_time;
|
||||||
|
ULARGE_INTEGER ul;
|
||||||
|
GetSystemTimeAsFileTime(&CurrentTime);
|
||||||
|
ul.LowPart = CurrentTime.dwLowDateTime;
|
||||||
|
ul.HighPart = CurrentTime.dwHighDateTime;
|
||||||
|
cur_time = ul.QuadPart;
|
||||||
|
cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */
|
||||||
|
cur_time /= 10; /* nanoseconds > microseconds */
|
||||||
|
return cur_time;
|
||||||
|
#else
|
||||||
|
struct timeval tv;
|
||||||
|
struct timezone tz;
|
||||||
|
gettimeofday(&tv, &tz);
|
||||||
|
return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int x, pass = 0, fail = 0, nop = 0;
|
int x, pass = 0, fail = 0, nop = 0;
|
||||||
|
@ -70,7 +70,6 @@ extern const struct ltc_prng_descriptor no_prng_desc;
|
|||||||
int sorter(const void *a, const void *b);
|
int sorter(const void *a, const void *b);
|
||||||
void tally_results(int type);
|
void tally_results(int type);
|
||||||
ulong64 rdtsc (void);
|
ulong64 rdtsc (void);
|
||||||
ulong64 epoch_usec(void);
|
|
||||||
|
|
||||||
void t_start(void);
|
void t_start(void);
|
||||||
ulong64 t_read(void);
|
ulong64 t_read(void);
|
||||||
|
@ -1,35 +1,5 @@
|
|||||||
#include <tomcrypt_test.h>
|
#include <tomcrypt_test.h>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#include <windows.h> /* GetSystemTimeAsFileTime */
|
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* microseconds since 1970 (UNIX epoch) */
|
|
||||||
ulong64 epoch_usec(void)
|
|
||||||
{
|
|
||||||
#if defined(LTC_NO_TEST_TIMING)
|
|
||||||
return 0;
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
FILETIME CurrentTime;
|
|
||||||
ulong64 cur_time;
|
|
||||||
ULARGE_INTEGER ul;
|
|
||||||
GetSystemTimeAsFileTime(&CurrentTime);
|
|
||||||
ul.LowPart = CurrentTime.dwLowDateTime;
|
|
||||||
ul.HighPart = CurrentTime.dwHighDateTime;
|
|
||||||
cur_time = ul.QuadPart;
|
|
||||||
cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */
|
|
||||||
cur_time /= 10; /* nanoseconds > microseconds */
|
|
||||||
return cur_time;
|
|
||||||
#else
|
|
||||||
struct timeval tv;
|
|
||||||
struct timezone tz;
|
|
||||||
gettimeofday(&tv, &tz);
|
|
||||||
return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list results[100];
|
struct list results[100];
|
||||||
int no_results;
|
int no_results;
|
||||||
int sorter(const void *a, const void *b)
|
int sorter(const void *a, const void *b)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user