uzinagased exemple code

This commit is contained in:
tth 2018-12-05 17:58:55 +01:00
parent 5aa4647df5
commit 15dd4f6296
4 changed files with 32 additions and 5 deletions

View File

@ -2,13 +2,20 @@
DATAFILE=/tmp/fake-datafile DATAFILE=/tmp/fake-datafile
#----- collect the datas
> ${DATAFILE} > ${DATAFILE}
for s in $(seq 1 20) for s in $(seq 1 20)
do do
v=$(./fake-values 2> /dev/null) v=$(./fake-values 2> /dev/null)
echo $s $v | tee -a ${DATAFILE} echo $s $v >> ${DATAFILE}
done done
awk '{print NR " " $2}' < ${DATAFILE} #----- do dome useless computations
awk '
NR==1 { debut = $2 }
{ print $2-debut, $3 }
' \
< ${DATAFILE}

View File

@ -12,7 +12,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "fake values - %s %s\n", __DATE__, __TIME__); fprintf(stderr, "fake values - %s %s\n", __DATE__, __TIME__);
verbosity = 1; verbosity = 1;
printf("%d\n", random1000(0)); printf("%f %d\n", dtime(), random1000(0));
return 0; return 0;
} }

21
funcs.c
View File

@ -4,16 +4,35 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h>
#include "funcs.h" #include "funcs.h"
extern int verbosity; extern int verbosity;
/* --------------------------------------------------------------- */
int random1000(int foo) int random1000(int foo)
{ {
int value; int value;
if (verbosity) if (verbosity)
fprintf(stderr, "%s(%d)\n", __func__, foo); fprintf(stderr, "%s(%d)\n", __func__, foo);
value = rand() % 1000; value = rand() % 1000;
return value; 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;
}
/* --------------------------------------------------------------- */

View File

@ -3,4 +3,5 @@
*/ */
int random1000(int mode); int random1000(int mode);
double dtime(void);