source:
benchmark/basic/fetch_add.c
@
a7efc96
Last change on this file since a7efc96 was 525b5ef, checked in by , 5 years ago | |
---|---|
|
|
File size: 571 bytes |
Rev | Line | |
---|---|---|
[6aa537a4] | 1 | #include <stdio.h> |
2 | ||
3 | #include "bench.h" | |
4 | ||
[525b5ef] | 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 | ||
[6aa537a4] | 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 | ||
[b4107c8] | 16 | int main( int argc, char * argv[] ) { |
17 | BENCH_START() | |
[6aa537a4] | 18 | BENCH( |
[b4107c8] | 19 | for (size_t i = 0; i < times; i++) { |
[6aa537a4] | 20 | do_call(); |
21 | }, | |
22 | result | |
23 | ) | |
[b4107c8] | 24 | printf( "%g\n", result ); |
[6aa537a4] | 25 | } |
[b4107c8] | 26 | |
27 | // Local Variables: // | |
28 | // tab-width: 4 // | |
29 | // End: // |
Note: See TracBrowser
for help on using the repository browser.