Improved time source for test programs.
This commit is contained in:
parent
466a502adf
commit
5eca7d7f17
@ -15,18 +15,15 @@ Here is a simple example of how to use LibHashSet in your application:
|
||||
|
||||
```C
|
||||
#include <hash_set.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SEED ((uint32_t)time(NULL))
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint64_t item;
|
||||
uintptr_t cursor = 0U;
|
||||
|
||||
/* create new hash set instance */
|
||||
hash_set64_t* const hash_set = hash_set_create64(0U, -1.0, SEED);
|
||||
hash_set64_t* const hash_set = hash_set_create64(0U, -1.0, 42U);
|
||||
if (!hash_set)
|
||||
{
|
||||
fputs("Allocation has failed!\n", stderr);
|
||||
|
@ -6,11 +6,8 @@
|
||||
#include <hash_map.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
#include "input.h"
|
||||
|
||||
#define SEED ((uint32_t)time(NULL))
|
||||
|
||||
/* ========================================================================= */
|
||||
/* MAIN */
|
||||
/* ========================================================================= */
|
||||
@ -26,7 +23,7 @@ int main(void)
|
||||
HASHSET_VERSION_MAJOR, HASHSET_VERSION_MINOR, HASHSET_VERSION_PATCH, HASHSET_BUILD_DATE);
|
||||
|
||||
/* create new hash map instance */
|
||||
hash_map = hash_map_create64(0U, -1.0, SEED);
|
||||
hash_map = hash_map_create64(0U, -1.0, 42U);
|
||||
if (!hash_map)
|
||||
{
|
||||
fputs("Allocation has failed!\n", stderr);
|
||||
|
@ -6,11 +6,8 @@
|
||||
#include <hash_set.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
#include "input.h"
|
||||
|
||||
#define SEED ((uint32_t)time(NULL))
|
||||
|
||||
/* ========================================================================= */
|
||||
/* MAIN */
|
||||
/* ========================================================================= */
|
||||
@ -26,7 +23,7 @@ int main(void)
|
||||
HASHSET_VERSION_MAJOR, HASHSET_VERSION_MINOR, HASHSET_VERSION_PATCH, HASHSET_BUILD_DATE);
|
||||
|
||||
/* create new hash set instance */
|
||||
hash_set = hash_set_create64(0U, -1.0, SEED);
|
||||
hash_set = hash_set_create64(0U, -1.0, 42U);
|
||||
if (!hash_set)
|
||||
{
|
||||
fputs("Allocation has failed!\n", stderr);
|
||||
|
@ -4,9 +4,10 @@
|
||||
/******************************************************************************/
|
||||
|
||||
#include "tests.h"
|
||||
#include "../../shared/include/time_in.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
#define RUN_TEST_CASE(X) do \
|
||||
{ \
|
||||
@ -17,7 +18,7 @@
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define SEED ((uint32_t)time(NULL))
|
||||
#define SEED ((uint32_t)clock_now())
|
||||
|
||||
/* ========================================================================= */
|
||||
/* MAIN */
|
||||
|
@ -40,11 +40,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\shared\src\random_in.c" />
|
||||
<ClCompile Include="..\shared\src\time_in.c" />
|
||||
<ClCompile Include="src\main.c" />
|
||||
<ClCompile Include="src\tests.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\shared\include\random_in.h" />
|
||||
<ClInclude Include="..\shared\include\time_in.h" />
|
||||
<ClInclude Include="src\tests.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -24,6 +24,9 @@
|
||||
<ClCompile Include="..\shared\src\random_in.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\shared\src\time_in.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\tests.h">
|
||||
@ -32,5 +35,8 @@
|
||||
<ClInclude Include="..\shared\include\random_in.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\shared\include\time_in.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -4,9 +4,10 @@
|
||||
/******************************************************************************/
|
||||
|
||||
#include "tests.h"
|
||||
#include "../../shared/include/time_in.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
#define RUN_TEST_CASE(X) do \
|
||||
{ \
|
||||
@ -17,7 +18,7 @@
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define SEED ((uint32_t)time(NULL))
|
||||
#define SEED ((uint32_t)clock_now())
|
||||
|
||||
/* ========================================================================= */
|
||||
/* MAIN */
|
||||
|
@ -40,11 +40,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\shared\src\random_in.c" />
|
||||
<ClCompile Include="..\shared\src\time_in.c" />
|
||||
<ClCompile Include="src\main.c" />
|
||||
<ClCompile Include="src\tests.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\shared\include\random_in.h" />
|
||||
<ClInclude Include="..\shared\include\time_in.h" />
|
||||
<ClInclude Include="src\tests.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -24,6 +24,9 @@
|
||||
<ClCompile Include="..\shared\src\random_in.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\shared\src\time_in.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\tests.h">
|
||||
@ -32,5 +35,8 @@
|
||||
<ClInclude Include="..\shared\include\random_in.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\shared\include\time_in.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
14
test/shared/include/time_in.h
Normal file
14
test/shared/include/time_in.h
Normal file
@ -0,0 +1,14 @@
|
||||
/******************************************************************************/
|
||||
/* HashSet for C99, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
||||
/* This work has been released under the CC0 1.0 Universal license! */
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef _TEST_TIME_INCLUDED
|
||||
#define _TEST_TIME_INCLUDED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint64_t clock_now(void);
|
||||
|
||||
#endif /*_TEST_TIME_INCLUDED*/
|
31
test/shared/src/time_in.c
Normal file
31
test/shared/src/time_in.c
Normal file
@ -0,0 +1,31 @@
|
||||
/******************************************************************************/
|
||||
/* HashSet for C99, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
||||
/* This work has been released under the CC0 1.0 Universal license! */
|
||||
/******************************************************************************/
|
||||
|
||||
#include "../include/time_in.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# include <Windows.h>
|
||||
#else
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
uint64_t clock_now(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER counter;
|
||||
if (QueryPerformanceCounter(&counter))
|
||||
{
|
||||
return counter.QuadPart;
|
||||
}
|
||||
#else
|
||||
struct timespec spec;
|
||||
if (!clock_gettime(CLOCK_MONOTONIC, &spec))
|
||||
{
|
||||
return (((uint64_t)spec.tv_sec) << 32) | (((uint64_t)spec.tv_nsec) & UINT64_C(0xFFFFFFFF));
|
||||
}
|
||||
#endif
|
||||
return 0U;
|
||||
}
|
Loading…
Reference in New Issue
Block a user