Browse Source

time to optimize for velocity

master
tth 3 years ago
parent
commit
7157ce47a3
  1. 27
      essai.c
  2. 2
      lib/Makefile
  3. 9
      lib/fimg-math.c

27
essai.c

@ -14,21 +14,11 @@ @@ -14,21 +14,11 @@
int verbosity;
/* --------------------------------------------------------------------- */
void fait_un_dessin(char *fname)
void fait_un_dessin(FloatImg *dessin)
{
FloatImg dessin;
double tb;
puts("");
fimg_timer_set(0);
fimg_create(&dessin, 3200, 2400, 3);
fimg_draw_something(&dessin);
fimg_dump_to_file(&dessin, "dessin.fimg", 0);
fimg_destroy(&dessin);
tb = fimg_timer_get(0);
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
fimg_draw_something(dessin);
puts("");
}
/* --------------------------------------------------------------------- */
void help(int k)
@ -60,10 +50,17 @@ if (verbosity) fimg_print_version(0); @@ -60,10 +50,17 @@ if (verbosity) fimg_print_version(0);
fimg_create(&fimgA, W, H, 3);
fimg_create(&fimgB, W, H, 3);
fimg_timer_set(0);
fimg_drand48(&fimgB, 100.0);
fimg_drand48(&fimgA, 100.0);
fimg_add(&fimgA, &fimgB, &fimgA);
fimg_timer_set(0);
#define NBP 500
for (foo=0; foo<NBP; foo++) {
if (verbosity) {
printf("%5d / %5d\n", foo, NBP);
}
fait_un_dessin(&fimgB);
fimg_add(&fimgA, &fimgB, &fimgA);
fimg_mul(&fimgA, &fimgB, &fimgA);
}
tb = fimg_timer_get(0);
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0);

2
lib/Makefile

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
# building the base library
#
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
COPT = -Wall -fpic -g -no-pie -pg -DDEBUG_LEVEL=0
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
fimg-timers.o operators.o fimg-2gray.o
DEPS = Makefile ../floatimg.h

9
lib/fimg-math.c

@ -117,9 +117,16 @@ int nbre, idx; @@ -117,9 +117,16 @@ int nbre, idx;
fprintf(stderr, ">>> %s ( %p %g )\n", __func__, fi, kmul);
#endif
nbre = fi->width * fi->height * fi->type;
if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return;
}
nbre = fi->width * fi->height;
for (idx=0; idx<nbre; idx++) {
fi->R[idx] = drand48() * kmul;
fi->G[idx] = drand48() * kmul;
fi->B[idx] = drand48() * kmul;
}
}

Loading…
Cancel
Save