[gnumeric] solver: improve timer resolution.



commit 4622c9fbb5a97df8fbc18fe86d14e029f57968d0
Author: Morten Welinder <terra gnome org>
Date:   Wed Jun 2 14:29:15 2010 -0400

    solver: improve timer resolution.

 src/tools/ChangeLog    |    3 +++
 src/tools/gnm-solver.c |   15 ++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index aaa9a23..83c1555 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,5 +1,8 @@
 2010-06-02  Morten Welinder  <terra gnome org>
 
+	* gnm-solver.c (gnm_solver_set_status, gnm_solver_elapsed):
+	Improve timer resolution.
+
 	* gnm-solver.h (GnmSolver): Add new starttime and endtime members.
 
 	* gnm-solver.c (gnm_solver_set_status): Set starttime and endtime
diff --git a/src/tools/gnm-solver.c b/src/tools/gnm-solver.c
index 7826493..031254f 100644
--- a/src/tools/gnm-solver.c
+++ b/src/tools/gnm-solver.c
@@ -889,6 +889,15 @@ gnm_solver_stop (GnmSolver *sol, GError **err)
 	return res;
 }
 
+static double
+current_time (void)
+{
+	GTimeVal now;
+	g_get_current_time (&now);
+	return now.tv_sec + (now.tv_usec / 1e6);
+}
+
+
 double
 gnm_solver_elapsed (GnmSolver *solver)
 {
@@ -900,7 +909,7 @@ gnm_solver_elapsed (GnmSolver *solver)
 		return 0;
 
 	endtime = (solver->endtime < 0)
-		? time (NULL)
+		? current_time ()
 		: solver->endtime;
 
 	return endtime - solver->starttime;
@@ -979,12 +988,12 @@ gnm_solver_set_status (GnmSolver *solver, GnmSolverStatus status)
 
 	if (status == GNM_SOLVER_STATUS_RUNNING)
 		g_object_set (G_OBJECT (solver),
-			      "starttime", (double)time (NULL),
+			      "starttime", current_time (),
 			      "endtime", (double)-1,
 			      NULL);
 	else if (old_status == GNM_SOLVER_STATUS_RUNNING)
 		g_object_set (G_OBJECT (solver),
-			      "endtime", (double)time (NULL),
+			      "endtime", current_time (),
 			      NULL);
 }
 



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