source:
benchmark/basic/fetch_add.c@
f2ff0a6
| Last change on this file since f2ff0a6 was 525b5ef, checked in by , 6 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.