source: benchmark/readyQ/yield.cpp @ 86b8d16

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 86b8d16 was 9cf2b0f, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Updated yield benchmarks to be more consistents.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "rq_bench.hpp"
2#include <libfibre/fibre.h>
3
4volatile bool run = false;
5volatile unsigned long long global_counter;
6
7
8void fibre_main() {
9        fibre_park();
10        unsigned long long count = 0;
11        for(;;) {
12                Fibre::forceYield();
13                count++;
14                if( clock_mode && stop) break;
15                if(!clock_mode && count >= stop_count) break;
16        }
17
18        __atomic_fetch_add(&global_counter, count, __ATOMIC_SEQ_CST);
19        __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
20}
21
22int main(int argc, char * argv[]) {
23        option_t opt[] = {
24                BENCH_OPT
25        };
26        BENCH_OPT_PARSE("libfibre yield benchmark");
27
28        {
29                printf("Running %d threads on %d processors for %lf seconds\n", nthreads, nprocs, duration);
30
31                FibreInit(1, nprocs);
32                uint64_t start, end;
33                {
34                        threads_left = nthreads;
35                        Fibre * threads[nthreads];
36                        for(unsigned i = 0; i < nthreads; i++) {
37                                threads[i] = new Fibre( reinterpret_cast<void (*)(void *)>(fibre_main), nullptr );
38                        }
39                        printf("Starting\n");
40                        bool is_tty = isatty(STDOUT_FILENO);
41                        start = timeHiRes();
42
43                        for(unsigned i = 0; i < nthreads; i++ ) {
44                                fibre_unpark( threads[i] );
45                        }
46                        wait<Fibre>(start, is_tty);
47
48                        stop = true;
49                        end = timeHiRes();
50                        for(unsigned i = 0; i < nthreads; i++ ) {
51                                fibre_join( threads[i], nullptr );
52                        }
53                }
54
55                printf("Duration (ms)        : %'ld\n", to_miliseconds(end - start));
56                printf("Number of processors : %'d\n", nprocs);
57                printf("Number of threads    : %'d\n", nthreads);
58                printf("Total Operations(ops): %'15llu\n", global_counter);
59                printf("Ops per second       : %'18.2lf\n", ((double)global_counter) / to_fseconds(end - start));
60                printf("ns per ops           : %'18.2lf\n", ((double)(end - start)) / global_counter);
61                printf("Ops per threads      : %'15llu\n", global_counter / nthreads);
62                printf("Ops per procs        : %'15llu\n", global_counter / nprocs);
63                printf("Ops/sec/procs        : %'18.2lf\n", (((double)global_counter) / nprocs) / to_fseconds(end - start));
64                printf("ns per ops/procs     : %'18.2lf\n", ((double)(end - start)) / (global_counter / nprocs));
65                fflush(stdout);
66        }
67}
Note: See TracBrowser for help on using the repository browser.