help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] [Fwd: Higher resolution glp_time under POSIX]


From: Andrew Makhorin
Subject: [Help-glpk] [Fwd: Higher resolution glp_time under POSIX]
Date: Thu, 02 Oct 2014 00:09:26 +0400

-------- Forwarded Message --------
From: C Blake <address@hidden>
Reply-to: C Blake <address@hidden>
To: address@hidden
Subject: Higher resolution glp_time under POSIX
Date: Wed, 1 Oct 2014 07:41:17 -0400

Hey.  About 55% of the test programs in examples/*.mod run in
under a single millisecond on my test machine.  It is hard to
even see that with the current code.

glp_time() truncates returned time to milliseconds (the nearest
integer value).  That rounding is unnecessary since you are
already using 'double' as the return value of glp_time aka xtime.
All the call sites seem to correctly handle the double return
value as well (..except one #if 0 removed glp_long t = xtime()
in glpios09.c which if reverted via #if 1 would even continue to
work just rounded to the nearest millisecond by the usual C rule
of truncating on conversion to an integer type).

This simple patch increases the resolution of glp_time() and its
use in the glpsol program.  It does not change the units from ms.
Fractional ms are simply kept as part of the double.  All call
sites using xtime/xdifftime will just get more precision in their
time differences.  It is hard to imagine that extra resolution
hurting anything.  (It would be better for anything that actually
depended on coarse resolution to explicitly round anyway...).

cb


diff -ruw glpk-4.54/src/env/time.c glpk-4.54-cb/src/env/time.c
--- glpk-4.54/src/env/time.c    2014-03-28 05:00:00.000000000 -0400
+++ glpk-4.54-cb/src/env/time.c 2014-10-01 07:03:38.772426242 -0400
@@ -62,7 +62,7 @@
       xassert(j >= 0);
       t = ((((double)(j - EPOCH) * 24.0 + (double)tm->tm_hour) * 60.0 +
          (double)tm->tm_min) * 60.0 + (double)tm->tm_sec) * 1000.0 +
-         (double)(tv.tv_usec / 1000);
+         (tv.tv_usec /(double) 1000);
       return t;
 }
 
diff -ruw glpk-4.54/src/glpapi21.c glpk-4.54-cb/src/glpapi21.c
--- glpk-4.54/src/glpapi21.c    2014-10-01 06:49:36.208892593 -0400
+++ glpk-4.54-cb/src/glpapi21.c 2014-10-01 06:48:57.400014059 -0400
@@ -1309,7 +1309,7 @@
          xassert(csa != csa);
       /*--------------------------------------------------------------*/
       /* display statistics */
-      xprintf("Time used:   %.1f secs\n", xdifftime(xtime(), start));
+      xprintf("Time used:   %.6f secs\n", xdifftime(xtime(), start));
 #if 0 /* 16/II-2012 */
       {  glp_long tpeak;
          char buf[50];






reply via email to

[Prev in Thread] Current Thread [Next in Thread]