source: benchmark/basic/fetch_add.c @ 7a0e8c8

Last change on this file since 7a0e8c8 was 525b5ef, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add documentation

  • Property mode set to 100644
File size: 571 bytes
Line 
1#include <stdio.h>
2
3#include "bench.h"
4
5// Does a "lock add" on entry and a "lock sub" on exit => 2 atomic instructions making it the most expensive
6// atomic test.
7
8volatile int value;
9
10void __attribute__((noinline)) do_call() {
11        __atomic_add_fetch( &value, 1, __ATOMIC_SEQ_CST );
12        asm volatile ("");
13        __atomic_sub_fetch( &value, 1, __ATOMIC_SEQ_CST );
14}
15
16int main( int argc, char * argv[] ) {
17        BENCH_START()
18        BENCH(
19                for (size_t i = 0; i < times; i++) {
20                        do_call();
21                },
22                result
23        )
24        printf( "%g\n", result );
25}
26
27// Local Variables: //
28// tab-width: 4 //
29// End: //
Note: See TracBrowser for help on using the repository browser.