From dc913974638af5ba4b0d76bcb3b0efd838bf30a1 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sat, 16 Apr 2016 17:15:51 +0200 Subject: [PATCH 1/3] vim-patch:7.4.1285 Problem: Cannot measure elapsed time. Solution: Add reltimefloat(). https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06 Applied manually. None of the ifdef's applies anymore, and proftime_T was changed into an uint64_T, so the function profile_float to convert proftime_T to float is not needed in nvim. --- src/nvim/eval.c | 16 ++++++++++++++++ src/nvim/version.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d84bdfebfe..16a96ba29e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6850,6 +6850,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 }, { "remove", 2, 3, f_remove }, { "rename", 2, 2, f_rename }, @@ -15296,6 +15297,21 @@ static void f_uniq(typval_T *argvars, typval_T *rettv) do_sort_uniq(argvars, rettv, false); } +// +// "reltimefloat()" function +// +static void f_reltimefloat(typval_T *argvars , typval_T *rettv) + FUNC_ATTR_NONNULL_ALL +{ + proftime_T tm; + + rettv->v_type = VAR_FLOAT; + rettv->vval.v_float = 0; + if (list2proftime(&argvars[0], &tm) == OK) { + rettv->vval.v_float = ((float_T)tm) / 1000000000; + } +} + /* * "soundfold({word})" function */ diff --git a/src/nvim/version.c b/src/nvim/version.c index 637b3778a7..e0bd83434c 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -393,7 +393,7 @@ static int included_patches[] = { // 1288 NA // 1287 NA // 1286 NA - // 1285, + 1285, 1284, // 1283 NA 1282, From 65b74998723867c03683de8c6b71b5a71b5a7c59 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sat, 16 Apr 2016 17:48:45 +0200 Subject: [PATCH 2/3] vim-patch:cb00f03 Add missing test file. https://github.com/vim/vim/commit/cb00f039332d3188931035e9d07144546fdea78a Converted to a lua test. Change the tolerance of the test to avoid false positives on travis. --- test/functional/eval/reltime_spec.lua | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/functional/eval/reltime_spec.lua diff --git a/test/functional/eval/reltime_spec.lua b/test/functional/eval/reltime_spec.lua new file mode 100644 index 0000000000..da55a3fac3 --- /dev/null +++ b/test/functional/eval/reltime_spec.lua @@ -0,0 +1,36 @@ +local helpers = require('test.functional.helpers') +local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok +local neq, execute, funcs = helpers.neq, helpers.execute, helpers.funcs +local reltime, reltimestr, reltimefloat = funcs.reltime, funcs.reltimestr, funcs.reltimefloat + +describe('reltimestr(), reltimefloat()', function() + before_each(clear) + + it('Checks', function() + local now = reltime() + execute('sleep 10m') + local later = reltime() + local elapsed = reltime(now) + + neq(reltimestr(elapsed), '0.0') + ok(reltimefloat(elapsed) > 0.0) + -- original vim test for < 0.1, but easily fails on travis + ok(nil ~= string.match(reltimestr(elapsed), "0%.")) + ok(reltimefloat(elapsed) < 1.0) + + local same = reltime(now, now) + local samestr = string.gsub(reltimestr(same), ' ', '') + samestr = string.sub(samestr, 1, 5) + + eq('0.000', samestr) + eq(0.0, reltimefloat(same)) + + local differs = reltime(now, later) + neq(reltimestr(differs), '0.0') + ok(reltimefloat(differs) > 0.0) + -- original vim test for < 0.1, but easily fails on travis + ok(nil ~= string.match(reltimestr(differs), "0%.")) + ok(reltimefloat(differs) < 1.0) + + end) +end) From 219a8bdb3600bc2075cd6b84e64813874b4ed290 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sat, 16 Apr 2016 20:45:09 +0200 Subject: [PATCH 3/3] Add documentation for reltimefloat() from https://github.com/vim/vim/commit/03413f44167c4b5cd0012def9bb331e2518c83cf Also adjust the entries for reltime() and reltimestr(). --- runtime/doc/eval.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 99b8760402..1990cf735d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2009,6 +2009,7 @@ range( {expr} [, {max} [, {stride}]]) readfile( {fname} [, {binary} [, {max}]]) List get list of lines from file {fname} reltime( [{start} [, {end}]]) List get time value +reltimefloat( {time}) Float turn the time value into a Float reltimestr( {time}) String turn time value into a String remote_expr( {server}, {string} [, {idvar}]) String send expression @@ -5319,7 +5320,8 @@ readfile({fname} [, {binary} [, {max}]]) reltime([{start} [, {end}]]) *reltime()* Return an item that represents a time value. The format of the item depends on the system. It can be passed to - |reltimestr()| to convert it to a string. + |reltimestr()| to convert it to a string or |reltimefloat()| + to convert to a float. Without an argument it returns the current time. With one argument is returns the time passed since the time specified in the argument. @@ -5327,7 +5329,16 @@ reltime([{start} [, {end}]]) *reltime()* and {end}. The {start} and {end} arguments must be values returned by reltime(). - {only available when compiled with the |+reltime| feature} + +reltimefloat({time}) *reltimefloat()* + Return a Float that represents the time value of {time}. + Unit of time is seconds. + Example: + let start = reltime() + call MyFunction() + let seconds = reltimefloat(reltime(start)) + See the note of reltimestr() about overhead. + Also see |profiling|. reltimestr({time}) *reltimestr()* Return a String that represents the time value of {time}. @@ -5337,12 +5348,10 @@ reltimestr({time}) *reltimestr()* call MyFunction() echo reltimestr(reltime(start)) < Note that overhead for the commands will be added to the time. - The accuracy depends on the system. Leading spaces are used to make the string align nicely. You can use split() to remove it. > echo split(reltimestr(reltime(start)))[0] < Also see |profiling|. - {only available when compiled with the |+reltime| feature} *remote_expr()* *E449* remote_expr({server}, {string} [, {idvar}])