diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4564d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# ignore final executable +mbw diff --git a/mbw.1 b/mbw.1 index 23514f8..d383d50 100644 --- a/mbw.1 +++ b/mbw.1 @@ -21,7 +21,8 @@ Quiet; suppress informational messages. Suppress printing the average of each test. .B .IP "\-n " -Select number of loops per test +Select number of loops per test, 0 to loop forever, press enter to reset the +running average. .B .IP "\-t " Select tests to be run. If no -t parameters are given the default is to run all tests. -t0: memcpy() test, -t1: dumb (b[i]=a[i] style) test, -t2: memcpy() with arbitrary block size diff --git a/mbw.c b/mbw.c index c2e90e1..b12ca4f 100644 --- a/mbw.c +++ b/mbw.c @@ -13,6 +13,7 @@ #include #include #include +#include /* how many runs to average by default */ #define DEFAULT_NR_LOOPS 10 @@ -183,6 +184,8 @@ int main(int argc, char **argv) /* how many runs to average? */ int nr_loops=DEFAULT_NR_LOOPS; + /* number of iterations for calculating the average when nr_loops is 0 */ + int avg_count = 0; /* fixed memcpy block size for -t2 */ unsigned long long block_size=DEFAULT_BLOCK_SIZE; /* show average, -a */ @@ -238,9 +241,13 @@ int main(int argc, char **argv) tests[2]=1; } - if( nr_loops==0 && ((tests[0]+tests[1]+tests[2]) != 1) ) { - printf("Error: nr_loops can be zero if only one test selected!\n"); - exit(1); + if(nr_loops == 0) { + if(tests[0]+tests[1]+tests[2] != 1) { + printf("Error: nr_loops can be zero if only one test selected!\n"); + exit(1); + } + /* Allow stdin input to reset the average, and without blocking. */ + fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK); } if(optind 0) + { + if(te_sum) + { + printf("Resetting average\n"); + } + te_sum = 0; + avg_count = 0; + } + } } if(showavg) { printf("AVG\t");