aboutsummaryrefslogtreecommitdiff
path: root/src/shell.c.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/shell.c.in')
-rw-r--r--src/shell.c.in38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index a311d85c4..3b797223a 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -106,6 +106,9 @@ typedef sqlite3_uint64 u64;
typedef unsigned char u8;
#include <ctype.h>
#include <stdarg.h>
+#ifndef _WIN32
+# include <sys/time.h>
+#endif
#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
@@ -267,20 +270,23 @@ static int cli_strncmp(const char *a, const char *b, size_t n){
return strncmp(a,b,n);
}
-/* Return the current wall-clock time */
+/* Return the current wall-clock time in microseconds since the
+** Unix epoch (1970-01-01T00:00:00Z)
+*/
static sqlite3_int64 timeOfDay(void){
- static sqlite3_vfs *clockVfs = 0;
- sqlite3_int64 t;
- if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
- if( clockVfs==0 ) return 0; /* Never actually happens */
- if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
- clockVfs->xCurrentTimeInt64(clockVfs, &t);
- }else{
- double r;
- clockVfs->xCurrentTime(clockVfs, &r);
- t = (sqlite3_int64)(r*86400000.0);
- }
+#if defined(_WIN32)
+ sqlite3_uint64 t;
+ FILETIME tm;
+ GetSystemTimePreciseAsFileTime(&tm);
+ t = ((u64)tm.dwHighDateTime<<32) | (u64)tm.dwLowDateTime;
+ t += 116444736000000000LL;
+ t /= 10;
return t;
+#else
+ struct timeval sNow;
+ (void)gettimeofday(&sNow,0);
+ return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
+#endif
}
#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
@@ -325,8 +331,8 @@ static void endTimer(FILE *out){
sqlite3_int64 iEnd = timeOfDay();
struct rusage sEnd;
getrusage(RUSAGE_SELF, &sEnd);
- sqlite3_fprintf(out, "Run Time: real %.3f user %f sys %f\n",
- (iEnd - iBegin)*0.001,
+ sqlite3_fprintf(out, "Run Time: real %.6f user %f sys %f\n",
+ (iEnd - iBegin)*0.000001,
timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
}
@@ -404,8 +410,8 @@ static void endTimer(FILE *out){
FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
sqlite3_int64 ftWallEnd = timeOfDay();
getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
- sqlite3_fprintf(out, "Run Time: real %.3f user %f sys %f\n",
- (ftWallEnd - ftWallBegin)*0.001,
+ sqlite3_fprintf(out, "Run Time: real %.6f user %f sys %f\n",
+ (ftWallEnd - ftWallBegin)*0.000001,
timeDiff(&ftUserBegin, &ftUserEnd),
timeDiff(&ftKernelBegin, &ftKernelEnd));
}