1 /* benchtime.h -- header file for MPFRbench 2 3 Copyright 1999, 2001-2023 Free Software Foundation, Inc. 4 Contributed by the AriC and Caramba projects, INRIA. 5 6 This file is part of the GNU MPFR Library. 7 8 The GNU MPFR Library is free software; you can redistribute it and/or modify 9 it under the terms of the GNU Lesser General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or (at your 11 option) any later version. 12 13 The GNU MPFR Library is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 License for more details. 17 18 You should have received a copy of the GNU Lesser General Public License 19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 20 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 24 /* compute the time to run accurately niter calls of the function for any 25 number of inputs */ 26 #define DECLARE_ACCURATE_TIME_NOP(func, funccall) \ 27 unsigned long int ACCURATE_TIME_NOP##func( unsigned long int niter, int n, mpfr_t* z, mpfr_t* x, mpfr_t* y, int nop);\ 28 unsigned long int ACCURATE_TIME_NOP##func( unsigned long int niter, int n, mpfr_t* z, mpfr_t* x, mpfr_t* y, int nop)\ 29 { \ 30 unsigned long int ti, i; int kn; \ 31 unsigned long int t0 = get_cputime (); \ 32 for (i = niter, kn=0; i > 0; i--) \ 33 { \ 34 funccall; \ 35 kn++; if (kn==n) kn = 0; \ 36 } \ 37 ti = get_cputime () - t0; \ 38 /* following lines are appended to avoid warnings but minimize the number \ 39 of macros */ \ 40 if (nop==2) y = NULL; \ 41 return ti; \ 42 } 43 44 /* address of the function to time accurately niter calls of func */ 45 #define ADDR_ACCURATE_TIME_NOP(func) ACCURATE_TIME_NOP##func 46 47 /* address of the function to time one call of func */ 48 #define ADDR_TIME_NOP(func) TIME_NOP##func 49 50 51 /* compute the time to run one only call of the function with two inputs */ 52 #define DECLARE_TIME_NOP(func, funcall, nop) \ 53 DECLARE_ACCURATE_TIME_NOP(func, funcall) \ 54 double TIME_NOP##func(int n, mpfr_t* z, mpfr_t* x, mpfr_t* y); \ 55 double TIME_NOP##func(int n, mpfr_t* z, mpfr_t* x, mpfr_t* y) \ 56 { \ 57 double t; unsigned long int nbcall, mytime; \ 58 for (nbcall = 1, mytime=0; mytime<250000; nbcall<<=1) \ 59 { \ 60 mytime = ACCURATE_TIME_NOP##func(nbcall, n, z, x, y, nop); \ 61 } \ 62 t = (double) mytime/ nbcall ; \ 63 return t; \ 64 } 65 66 /* compute the time to run accurately niter calls of the function */ 67 /* functions with 2 operands */ 68 #define DECLARE_TIME_2OP(func) DECLARE_TIME_NOP(func, func(z[kn],x[kn],y[kn], MPFR_RNDN), 2 ) 69 /* functions with 1 operand */ 70 #define DECLARE_TIME_1OP(func) DECLARE_TIME_NOP(func, func(z[kn],x[kn], MPFR_RNDN), 1 ) 71