Skip to content

Commit 79c2c88

Browse files
committed
patch 7.4.1285
Problem: Cannot measure elapsed time. Solution: Add reltimefloat().
1 parent dc94a26 commit 79c2c88

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/eval.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@ static void f_pyeval(typval_T *argvars, typval_T *rettv);
690690
static void f_range(typval_T *argvars, typval_T *rettv);
691691
static void f_readfile(typval_T *argvars, typval_T *rettv);
692692
static void f_reltime(typval_T *argvars, typval_T *rettv);
693+
#ifdef FEAT_FLOAT
694+
static void f_reltimefloat(typval_T *argvars, typval_T *rettv);
695+
#endif
693696
static void f_reltimestr(typval_T *argvars, typval_T *rettv);
694697
static void f_remote_expr(typval_T *argvars, typval_T *rettv);
695698
static void f_remote_foreground(typval_T *argvars, typval_T *rettv);
@@ -8270,6 +8273,7 @@ static struct fst
82708273
{"range", 1, 3, f_range},
82718274
{"readfile", 1, 3, f_readfile},
82728275
{"reltime", 0, 2, f_reltime},
8276+
{"reltimefloat", 1, 1, f_reltimefloat},
82738277
{"reltimestr", 1, 1, f_reltimestr},
82748278
{"remote_expr", 2, 3, f_remote_expr},
82758279
{"remote_foreground", 1, 1, f_remote_foreground},
@@ -16010,6 +16014,26 @@ f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
1601016014
#endif
1601116015
}
1601216016

16017+
#ifdef FEAT_FLOAT
16018+
/*
16019+
* "reltimefloat()" function
16020+
*/
16021+
static void
16022+
f_reltimefloat(typval_T *argvars UNUSED, typval_T *rettv)
16023+
{
16024+
# ifdef FEAT_RELTIME
16025+
proftime_T tm;
16026+
# endif
16027+
16028+
rettv->v_type = VAR_FLOAT;
16029+
rettv->vval.v_float = 0;
16030+
# ifdef FEAT_RELTIME
16031+
if (list2proftime(&argvars[0], &tm) == OK)
16032+
rettv->vval.v_float = profile_float(&tm);
16033+
# endif
16034+
}
16035+
#endif
16036+
1601316037
/*
1601416038
* "reltimestr()" function
1601516039
*/

src/ex_cmds2.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,24 @@ profile_msg(proftime_T *tm)
10101010
return buf;
10111011
}
10121012

1013+
# if defined(FEAT_FLOAT) || defined(PROTO)
1014+
/*
1015+
* Return a float that represents the time in "tm".
1016+
*/
1017+
float_T
1018+
profile_float(proftime_T *tm)
1019+
{
1020+
# ifdef WIN3264
1021+
LARGE_INTEGER fr;
1022+
1023+
QueryPerformanceFrequency(&fr);
1024+
return (float_T)tm->QuadPart / (float_T)fr.QuadPart;
1025+
# else
1026+
return (float_T)tm->tv_sec + (float_T)tm->tv_usec / 1000000.0;
1027+
# endif
1028+
}
1029+
# endif
1030+
10131031
/*
10141032
* Put the time "msec" past now in "tm".
10151033
*/

src/proto/ex_cmds2.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void profile_start(proftime_T *tm);
1414
void profile_end(proftime_T *tm);
1515
void profile_sub(proftime_T *tm, proftime_T *tm2);
1616
char *profile_msg(proftime_T *tm);
17+
float_T profile_float(proftime_T *tm);
1718
void profile_setlimit(long msec, proftime_T *tm);
1819
int profile_passed_limit(proftime_T *tm);
1920
void profile_zero(proftime_T *tm);

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source test_glob2regpat.vim
99
source test_json.vim
1010
source test_lispwords.vim
1111
source test_menu.vim
12+
source test_reltime.vim
1213
source test_searchpos.vim
1314
source test_set.vim
1415
source test_sort.vim

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ static char *(features[]) =
747747

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1285,
750752
/**/
751753
1284,
752754
/**/

0 commit comments

Comments
 (0)