From f8722d817b1b8d1f7e138105f982a8a2f8c960bb Mon Sep 17 00:00:00 2001 From: Orestis <orestis.malaspinas@pm.me> Date: Wed, 27 Oct 2021 11:01:12 +0200 Subject: [PATCH] updated path for complexity slides --- slides/complexite.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/slides/complexite.md b/slides/complexite.md index 4c49e66..81cbb89 100644 --- a/slides/complexite.md +++ b/slides/complexite.md @@ -13,19 +13,36 @@ Comment mesurer l'efficacité d'un algorithme? Dépendant du **matériel**, du **compilateur**, des **options de compilation**, etc! -## Exemple: somme d'entiers +## Mesure du temps CPU ```C #include <time.h> - struct timespec tstart={0,0}, tend={0,0}; clock_gettime(CLOCK_MONOTONIC, &tstart); // some computation clock_gettime(CLOCK_MONOTONIC, &tend); +printf("computation about %.5f seconds\n", + ((double)tend.tv_sec + 1e-9*tend.tv_nsec) - + ((double)tstart.tv_sec + 1e-9*tstart.tv_nsec)); +``` + +# Programme simple: mesure du temps CPU -printf("some_long_computation took about %.5f seconds\n", - ((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec)); +## Preuve sur un [petit exemple](../source_codes/complexity/sum.c) + +```bash +source_codes/complexity$ make bench +RUN ONCE O0 +the computation of 199972.740622 took about 0.00836 seconds +RUN ONCE O3 +the computation of 199972.740622 took about 0.00203 seconds +RUN THOUSAND TIMES O0 +the computation of 199972740.621922 took about 0.00363 seconds +RUN THOUSAND TIMES O3 +the computation of 199972740.621922 took about 0.00046 seconds ``` -* Il est nécessaire d'avoir une mesure indépendante du matériel. +. . . + +* Il est nécessaire d'avoir une mesure indépendante du + matériel/compilateur/façon de mesurer. -- GitLab