Wednesday, December 23, 2009

Re: Best practice and enhance performance duration of vimscript

Mikołaj Machowski wrote:
> Dnia 23-12-2009 o godz. 13:19 Tim Chase napisał(a):
>> Mikołaj Machowski wrote:
>>>> I have all book on gvim but no one tells me the best practice to have
>>>> good performance when we write vimscript.
>>> 1. In regexps avoid when possible * wildcard.
>> I've never had problems with this, but it may affect long lines.
>
> Simple test on big file - trimming whitespaces from end of line:
>
> %s/\s*$//
> %s/\s\+$//
>
> Basically this is special case of my second tip - * matches everywhere,
> \+ tests if action is necessary.

Ah...I see where you were making the comparison now. To get accurate
differences in timing, you'd have to compare regexps that do the same
thing, So comparing the two would be done with

%s/\s\s*//g
%s/\s\+//g

which should time out negligibly the same (minus the extra character to
type in the 1st one :)


> Sad truth about such optimizations is that they often take more time to
> implement than actual savings during execution :D

oh, sooooo true. :) Unless a regex/batch change take more than about
1-2+ minutes to run, I never consider optimization on a micro level. I
burn enough braincells in other areas of life. Gotta save them where I can.

-tim


--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment