#pragma once #if defined(__cforall) extern "C" { #endif #include #include // uint64_t #include // sysconf #if ! defined(__cforall) #include #include #else } #include #endif static inline uint64_t bench_time() { struct timespec ts; clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); return 1000000000LL * ts.tv_sec + ts.tv_nsec; } // bench_time #if defined(__cforall) struct test_spinlock { volatile bool lock; }; static inline void lock( test_spinlock & this ) { for ( ;; ) { if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break; } } static inline void unlock( test_spinlock & this ) { __atomic_clear( &this.lock, __ATOMIC_RELEASE ); } #endif #ifndef BENCH_N #define BENCH_N 10000000 #endif size_t times = BENCH_N; #define BENCH_START() \ if ( argc > 2 ) exit( EXIT_FAILURE ); \ if ( argc == 2 ) { \ times = atoi( argv[1] ); \ } #define BENCH(statement, output) \ uint64_t StartTime, EndTime; \ StartTime = bench_time(); \ statement; \ EndTime = bench_time(); \ double output = (double)( EndTime - StartTime ) / times; #if defined(__cforall) Duration default_preemption() { return 0; } #endif #if defined(__U_CPLUSPLUS__) unsigned int uDefaultPreemption() { return 0; } #endif