Browse Source

uzinagased exemple code

master
tth 2 years ago
parent
commit
15dd4f6296
4 changed files with 32 additions and 5 deletions
  1. +10
    -3
      exemple.sh
  2. +1
    -1
      fake-values.c
  3. +20
    -1
      funcs.c
  4. +1
    -0
      funcs.h

+ 10
- 3
exemple.sh View File

@ -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}

+ 1
- 1
fake-values.c View File

@ -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;
}

+ 20
- 1
funcs.c View File

@ -4,16 +4,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#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;
}
/* --------------------------------------------------------------- */

+ 1
- 0
funcs.h View File

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

Loading…
Cancel
Save