Create new helper compiler_barrier to prevent compiler from over-optimizing bench.
This commit is contained in:
1 parent
af2fe9ccf9
commit
a36efcd888
2 files changed
+48
-7
No files matched your search
+16
-7
@@ -25,11 +25,14 @@
|
||||
#ifndef __COMMON_BENCH__H
|
||||
#define __COMMON_BENCH__H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* WINDOWS variant */
|
||||
#include <windows.h>
|
||||
|
||||
static unsigned long long
|
||||
static inline unsigned long long
|
||||
cputime (void)
|
||||
{
|
||||
LARGE_INTEGER freq, val;
|
||||
@@ -44,7 +47,7 @@ cputime (void)
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static unsigned long long
|
||||
static inline unsigned long long
|
||||
cputime (void)
|
||||
{
|
||||
#if defined(MULTI_THREAD_MEASURE)
|
||||
@@ -62,23 +65,24 @@ cputime (void)
|
||||
|
||||
#endif
|
||||
|
||||
unsigned long g_result;
|
||||
static unsigned long g_result;
|
||||
#if defined(MULTI_THREAD_MEASURE)
|
||||
M_THREAD_ATTR
|
||||
#endif
|
||||
unsigned int randValue = 0;
|
||||
static unsigned int randValue = 0;
|
||||
|
||||
static void rand_init(void)
|
||||
static inline void rand_init(void)
|
||||
{
|
||||
randValue = 0;
|
||||
}
|
||||
static unsigned int rand_get(void)
|
||||
|
||||
static inline unsigned int rand_get(void)
|
||||
{
|
||||
randValue = randValue * 31421U + 6927U;
|
||||
return randValue;
|
||||
}
|
||||
|
||||
static void test_function(const char str[], size_t n, void (*func)(size_t))
|
||||
static inline void test_function(const char str[], size_t n, void (*func)(size_t))
|
||||
{
|
||||
unsigned long long start, end;
|
||||
rand_init();
|
||||
@@ -123,4 +127,9 @@ static inline int get_cpu_count(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
void compiler_barrier(void *p);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user