Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore final executable
mbw
3 changes: 2 additions & 1 deletion mbw.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Quiet; suppress informational messages.
Suppress printing the average of each test.
.B
.IP "\-n <number>"
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 <number>"
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
Expand Down
32 changes: 29 additions & 3 deletions mbw.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

/* how many runs to average by default */
#define DEFAULT_NR_LOOPS 10
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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<argc) {
Expand Down Expand Up @@ -290,6 +297,25 @@ int main(int argc, char **argv)
te_sum+=te;
printf("%d\t", i);
printout(te, mt, testno);
/* 0 never terminates, print the curent average every loop */
if(nr_loops==0 && showavg)
{
char c[80];
++avg_count;
printf("AVG %d\t", avg_count);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not suppress this too, if -a was specified?

(sorry for the super slow responses)

printout(te_sum/avg_count, mt, testno);
/* any input resets the average, read all input available,
* in practice the input isn't likely raw, so press enter.*/
while(read(0, c, sizeof(c)) > 0)
{
if(te_sum)
{
printf("Resetting average\n");
}
te_sum = 0;
avg_count = 0;
}
}
}
if(showavg) {
printf("AVG\t");
Expand Down