diff options
author | tege <tege@gmplib.org> | 2001-02-02 22:33:08 +0100 |
---|---|---|
committer | tege <tege@gmplib.org> | 2001-02-02 22:33:08 +0100 |
commit | 99befcf5d7704bbc021902f4e43d22e72ba53605 (patch) | |
tree | a20bb5160728bd33e091218ba8dd50f6e0d04fa5 /demos/pexpr.c | |
parent | 7fa50497533ceb295911271119b44f91865d9d84 (diff) | |
download | gmp-99befcf5d7704bbc021902f4e43d22e72ba53605.tar.gz |
(TIME): New macro.
(main): Use TIME--print timing more accurately.
(setup_error_handler): Increase RLIMIT_DATA to 16 Mibyte.
Diffstat (limited to 'demos/pexpr.c')
-rw-r--r-- | demos/pexpr.c | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/demos/pexpr.c b/demos/pexpr.c index 6fdd33353..5bee89cf1 100644 --- a/demos/pexpr.c +++ b/demos/pexpr.c @@ -54,6 +54,23 @@ Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "gmp.h" +#define TIME(t,func) \ + do { int __t0, __times, __t, __tmp; \ + __times = 1; \ + __t0 = cputime (); \ + {func;} \ + __tmp = cputime () - __t0; \ + while (__tmp < 100) \ + { \ + __times <<= 1; \ + __t0 = cputime (); \ + for (__t = 0; __t < __times; __t++) \ + {func;} \ + __tmp = cputime () - __t0; \ + } \ + (t) = (double) __tmp / __times; \ + } while (0) + /* GMP version 1.x compatibility. */ #if ! (__GNU_MP_VERSION >= 2) typedef MP_INT __mpz_struct; @@ -169,7 +186,7 @@ setup_error_handler () limit.rlim_max = 4; setrlimit (RLIMIT_CPU, &limit); - limit.rlim_cur = limit.rlim_max = 4 * 1024 * 1024; + limit.rlim_cur = limit.rlim_max = 16 * 1024 * 1024; setrlimit (RLIMIT_DATA, &limit); getrlimit (RLIMIT_STACK, &limit); @@ -329,18 +346,15 @@ main (int argc, char **argv) continue; } - { - int t0; - - if (print_timing) - t0 = cputime (); - + if (print_timing) + { + double t; + TIME (t, mpz_eval_expr (r, e)); + printf ("computation took %.2f ms%s\n", t, newline); + } + else mpz_eval_expr (r, e); - if (print_timing) - printf ("computation took %d ms%s\n", cputime () - t0, newline); - } - if (flag_print) { size_t out_len; @@ -351,18 +365,14 @@ main (int argc, char **argv) tmp = malloc (out_len); if (print_timing) - t0 = cputime (); - - if (print_timing) - /* Print first half of message... */ - printf ("output conversion "); - - mpz_get_str (tmp, -base, r); - - if (print_timing) - /* ...print 2nd half of message unless we caught a time limit - and therefore longjmp'ed */ - printf ("took %d ms%s\n", cputime () - t0, newline); + { + double t; + printf ("output conversion "); + TIME (t, mpz_get_str (tmp, -base, r)); + printf ("took %.2f ms%s\n", t, newline); + } + else + mpz_get_str (tmp, -base, r); out_len = strlen (tmp); if (flag_splitup_output) |