source:
benchmark/basic/fetch_add.c
@
c4f8170
Last change on this file since c4f8170 was 525b5ef, checked in by , 5 years ago | |
---|---|
|
|
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 | |
8 | volatile int value; |
9 | |
10 | void __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 | |
16 | int 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.