To: vim_dev@googlegroups.com Subject: Patch 7.4.1285 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1285 Problem: Cannot measure elapsed time. Solution: Add reltimefloat(). Files: src/ex_cmds2.c, src/eval.c, src/proto/ex_cmds2.pro, src/testdir/test_reltime.vim, src/testdir/test_alot.vim *** ../vim-7.4.1284/src/ex_cmds2.c 2016-01-31 17:30:47.418544455 +0100 --- src/ex_cmds2.c 2016-02-07 21:06:36.249107436 +0100 *************** *** 1010,1015 **** --- 1010,1033 ---- 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". */ *** ../vim-7.4.1284/src/eval.c 2016-02-07 19:57:12.192788494 +0100 --- src/eval.c 2016-02-07 21:06:14.969330987 +0100 *************** *** 690,695 **** --- 690,698 ---- 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,8275 **** --- 8273,8279 ---- {"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,16015 **** --- 16014,16039 ---- #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 */ *** ../vim-7.4.1284/src/proto/ex_cmds2.pro 2016-01-19 13:21:55.837334377 +0100 --- src/proto/ex_cmds2.pro 2016-02-07 21:06:26.701207740 +0100 *************** *** 14,19 **** --- 14,20 ---- 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); *** ../vim-7.4.1284/src/testdir/test_reltime.vim 2016-02-07 21:18:51.793382319 +0100 --- src/testdir/test_reltime.vim 2016-02-07 21:17:34.222197665 +0100 *************** *** 0 **** --- 1,27 ---- + " Tests for reltime() + + if !has('reltime') || !has('float') + finish + endif + + func Test_reltime() + let now = reltime() + sleep 10m + let later = reltime() + let elapsed = reltime(now) + call assert_true(reltimestr(elapsed) =~ '0\.0') + call assert_true(reltimestr(elapsed) != '0.0') + call assert_true(reltimefloat(elapsed) < 0.1) + call assert_true(reltimefloat(elapsed) > 0.0) + + let same = reltime(now, now) + call assert_equal('0.000', split(reltimestr(same))[0][:4]) + call assert_equal(0.0, reltimefloat(same)) + + let differs = reltime(now, later) + call assert_true(reltimestr(differs) =~ '0\.0') + call assert_true(reltimestr(differs) != '0.0') + call assert_true(reltimefloat(differs) < 0.1) + call assert_true(reltimefloat(differs) > 0.0) + + endfunc *** ../vim-7.4.1284/src/testdir/test_alot.vim 2016-01-25 22:20:24.056402843 +0100 --- src/testdir/test_alot.vim 2016-02-07 21:07:53.276298287 +0100 *************** *** 9,14 **** --- 9,15 ---- 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 *** ../vim-7.4.1284/src/version.c 2016-02-07 20:28:55.988888338 +0100 --- src/version.c 2016-02-07 21:18:02.409901379 +0100 *************** *** 749,750 **** --- 749,752 ---- { /* Add new patch number below this line */ + /**/ + 1285, /**/ -- If Apple would build a car... ... it would be powered by the sun, be reliable, five times as fast and twice as easy to drive; but would only run on five percent of the roads. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///