ex-2/fast: print running time

This commit is contained in:
Michele Guerini Rocco 2020-05-27 21:15:06 +02:00
parent 383dbd6f38
commit f2679b8204

View File

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <gmp.h> #include <gmp.h>
#include <time.h>
/* The Euler-Mascheroni constant is here computed to /* The Euler-Mascheroni constant is here computed to
* arbitrary precision using GMP floating point numbers * arbitrary precision using GMP floating point numbers
@ -216,7 +217,12 @@ int main(int argc, char** argv) {
mpf_set_default_prec(prec + 64); mpf_set_default_prec(prec + 64);
mpf_t y; mpf_init(y); mpf_t y; mpf_init(y);
clock_t begin = clock();
mpf_gamma(y, digits); mpf_gamma(y, digits);
clock_t end = clock();
double time = (double)(end - begin)/CLOCKS_PER_SEC;
fprintf(stderr, "[main] running time: %gs\n", time);
// again, trick to avoid rounding // again, trick to avoid rounding
gmp_printf("%.*Ff\b \n", digits+1, y); gmp_printf("%.*Ff\b \n", digits+1, y);