diff --git a/exemple.sh b/exemple.sh index 3f6d81d..8a9f738 100755 --- a/exemple.sh +++ b/exemple.sh @@ -2,13 +2,20 @@ DATAFILE=/tmp/fake-datafile +#----- collect the datas > ${DATAFILE} for s in $(seq 1 20) do - v=$(./fake-values 2> /dev/null) - echo $s $v | tee -a ${DATAFILE} + echo $s $v >> ${DATAFILE} done -awk '{print NR " " $2}' < ${DATAFILE} +#----- do dome useless computations +awk ' + NR==1 { debut = $2 } + { print $2-debut, $3 } + ' \ +< ${DATAFILE} + + diff --git a/fake-values.c b/fake-values.c index 6b412ac..09f95bf 100644 --- a/fake-values.c +++ b/fake-values.c @@ -12,7 +12,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "fake values - %s %s\n", __DATE__, __TIME__); verbosity = 1; -printf("%d\n", random1000(0)); +printf("%f %d\n", dtime(), random1000(0)); return 0; } diff --git a/funcs.c b/funcs.c index 15cba7a..b099c2a 100644 --- a/funcs.c +++ b/funcs.c @@ -4,16 +4,35 @@ #include #include +#include #include "funcs.h" extern int verbosity; +/* --------------------------------------------------------------- */ + int random1000(int foo) { -int value; +int value; if (verbosity) fprintf(stderr, "%s(%d)\n", __func__, foo); value = rand() % 1000; return value; } + +/* --------------------------------------------------------------- */ + +double dtime(void) +{ +struct timeval tv; +int foo; + +foo = gettimeofday(&tv, NULL); +if (foo) fprintf(stderr, "got %d in %s\n", foo, __func__); + +return (double)tv.tv_sec + (double)tv.tv_usec / 1e6; +} + +/* --------------------------------------------------------------- */ + diff --git a/funcs.h b/funcs.h index 2319ac4..e142ca8 100644 --- a/funcs.h +++ b/funcs.h @@ -3,4 +3,5 @@ */ int random1000(int mode); +double dtime(void);