summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-07 21:19:28 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-07 21:19:28 +0100
commit79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06 (patch)
tree9af61874e83f9428b0b91e54328e3f92f7ed9f95
parentdc94a26a641914df5f1ba1ab47a5752e1137287e (diff)
patch 7.4.1285v7.4.1285
Problem: Cannot measure elapsed time. Solution: Add reltimefloat().
-rw-r--r--src/eval.c24
-rw-r--r--src/ex_cmds2.c18
-rw-r--r--src/proto/ex_cmds2.pro1
-rw-r--r--src/testdir/test_alot.vim1
-rw-r--r--src/version.c2
5 files changed, 46 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c
index c2d18aa869..787f0f0343 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -690,6 +690,9 @@ static void f_pyeval(typval_T *argvars, typval_T *rettv);
static void f_range(typval_T *argvars, typval_T *rettv);
static void f_readfile(typval_T *argvars, typval_T *rettv);
static void f_reltime(typval_T *argvars, typval_T *rettv);
+#ifdef FEAT_FLOAT
+static void f_reltimefloat(typval_T *argvars, typval_T *rettv);
+#endif
static void f_reltimestr(typval_T *argvars, typval_T *rettv);
static void f_remote_expr(typval_T *argvars, typval_T *rettv);
static void f_remote_foreground(typval_T *argvars, typval_T *rettv);
@@ -8270,6 +8273,7 @@ static struct fst
{"range", 1, 3, f_range},
{"readfile", 1, 3, f_readfile},
{"reltime", 0, 2, f_reltime},
+ {"reltimefloat", 1, 1, f_reltimefloat},
{"reltimestr", 1, 1, f_reltimestr},
{"remote_expr", 2, 3, f_remote_expr},
{"remote_foreground", 1, 1, f_remote_foreground},
@@ -16010,6 +16014,26 @@ f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
#endif
}
+#ifdef FEAT_FLOAT
+/*
+ * "reltimefloat()" function
+ */
+ static void
+f_reltimefloat(typval_T *argvars UNUSED, typval_T *rettv)
+{
+# ifdef FEAT_RELTIME
+ proftime_T tm;
+# endif
+
+ rettv->v_type = VAR_FLOAT;
+ rettv->vval.v_float = 0;
+# ifdef FEAT_RELTIME
+ if (list2proftime(&argvars[0], &tm) == OK)
+ rettv->vval.v_float = profile_float(&tm);
+# endif
+}
+#endif
+
/*
* "reltimestr()" function
*/
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 98b8c8fbb5..49e4d3df44 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -1010,6 +1010,24 @@ profile_msg(proftime_T *tm)
return buf;
}
+# if defined(FEAT_FLOAT) || defined(PROTO)
+/*
+ * Return a float that represents the time in "tm".
+ */
+ float_T
+profile_float(proftime_T *tm)
+{
+# ifdef WIN3264
+ LARGE_INTEGER fr;
+
+ QueryPerformanceFrequency(&fr);
+ return (float_T)tm->QuadPart / (float_T)fr.QuadPart;
+# else
+ return (float_T)tm->tv_sec + (float_T)tm->tv_usec / 1000000.0;
+# endif
+}
+# endif
+
/*
* Put the time "msec" past now in "tm".
*/
diff --git a/src/proto/ex_cmds2.pro b/src/proto/ex_cmds2.pro
index 54ccf12c30..a73e10f646 100644
--- a/src/proto/ex_cmds2.pro
+++ b/src/proto/ex_cmds2.pro
@@ -14,6 +14,7 @@ void profile_start(proftime_T *tm);
void profile_end(proftime_T *tm);
void profile_sub(proftime_T *tm, proftime_T *tm2);
char *profile_msg(proftime_T *tm);
+float_T profile_float(proftime_T *tm);
void profile_setlimit(long msec, proftime_T *tm);
int profile_passed_limit(proftime_T *tm);
void profile_zero(proftime_T *tm);
diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim
index 97454335de..e2956492f3 100644
--- a/src/testdir/test_alot.vim
+++ b/src/testdir/test_alot.vim
@@ -9,6 +9,7 @@ source test_glob2regpat.vim
source test_json.vim
source test_lispwords.vim
source test_menu.vim
+source test_reltime.vim
source test_searchpos.vim
source test_set.vim
source test_sort.vim
diff --git a/src/version.c b/src/version.c
index c2d75bbe82..ea0c770558 100644
--- a/src/version.c
+++ b/src/version.c
@@ -748,6 +748,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1285,
+/**/
1284,
/**/
1283,