source: benchmark/readyQ/yield.cpp @ 9d55ff6

ADTast-experimentalpthread-emulation
Last change on this file since 9d55ff6 was 8fe35be, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Fixed some benchmarks that were still using stack arrays

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