diff --git a/complexite.md b/slides/complexite.md similarity index 100% rename from complexite.md rename to slides/complexite.md diff --git a/source_codes/complexity/.gitignore b/source_codes/complexity/.gitignore index 92292873f791ed576373b70f2bd8011aa701bf90..7878686d5c5f4b1d1f8feb2a82f2c7292aa670c1 100644 --- a/source_codes/complexity/.gitignore +++ b/source_codes/complexity/.gitignore @@ -1 +1,6 @@ sum +sum_one +sum_one_opt +sum_thousand +sum_thousand_opt + diff --git a/source_codes/complexity/Makefile b/source_codes/complexity/Makefile index d7822ac93c5aaf6b38512758abde6dae01881871..71596615ba959b64dbe76a9fdefcd1240a127fa0 100644 --- a/source_codes/complexity/Makefile +++ b/source_codes/complexity/Makefile @@ -11,6 +11,26 @@ $(EXECS): %: %.c $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) @echo $@ >> .gitignore +bench: sum_one sum_one_opt sum_thousand sum_thousand_opt + @echo "RUN ONCE O0" && ./sum_one + @echo "RUN ONCE O3" && ./sum_one_opt + @echo "RUN THOUSAND TIMES O0" && ./sum_thousand + @echo "RUN THOUSAND TIMES O3" && ./sum_thousand_opt + + +sum_one: sum.c + $(CC) $(CFLAGS) -DSIZE=1000000 -DNUM_TIMES=1 -o $@ $< $(LDFLAGS) + +sum_one_opt: sum.c + $(CC) $(CFLAGS) -O3 -DSIZE=1000000 -DNUM_TIMES=1 -o $@ $< $(LDFLAGS) + +sum_thousand: sum.c + $(CC) $(CFLAGS) -DSIZE=1000000 -DNUM_TIMES=1000 -o $@ $< $(LDFLAGS) + +sum_thousand_opt: sum.c + $(CC) $(CFLAGS) -O3 -DSIZE=1000000 -DNUM_TIMES=1000 -o $@ $< $(LDFLAGS) + + .PHONY: clean all clean: diff --git a/source_codes/complexity/sum.c b/source_codes/complexity/sum.c index 4451354467ea6177e971f5fbc83a1e9122ea44f2..4a9780aba94c6454def947222c12d2c5b88738a8 100644 --- a/source_codes/complexity/sum.c +++ b/source_codes/complexity/sum.c @@ -2,8 +2,13 @@ #include <stdlib.h> #include <time.h> +#ifndef SIZE #define SIZE 1000000 +#endif + +#ifndef NUM_TIMES #define NUM_TIMES 10 +#endif void init(int n, double tab[]) { for (int i = 0; i < n; ++i) { @@ -30,7 +35,7 @@ int main() { s += sum(SIZE, tab); } clock_gettime(CLOCK_MONOTONIC, &tend); - printf("the computation of %f took about %.5f seconds\n", s, + printf("the computation took about %.5f seconds\n", (((double)tend.tv_sec + 1e-9 * tend.tv_nsec) - ((double)tstart.tv_sec + 1e-9 * tstart.tv_nsec)) / NUM_TIMES);