Re: performance of matchstr vs. substitute
- On Mon, 29 Oct 2001 at 11:32pm, Benji Fisher wrote:
> Hari Krishna Dara wrote:Ok, I finally had a chance to try the different options you have given. I
> > I thought matchstr should perform better than substitute, but I was wrong.
> > I have a very long list of absolute file names and I needed to extract the
> > extensions for each line in a script. Surprisingly, the following:
> > let type = substitute(getline("."), '^.*\.\([^.]*\)', '\1', '')
> > turned out faster than the following:
> > let type = matchstr(getline("."), '[^.]\+$')
> > Can anybody explain this ?
> > Thank you,
> > Hari
> Just a guess: the difference may be the regular expressions, not
> substitute() versus matchstr(). Try
> let type = matchstr(getline("."), '\.[^.]\+$')
> and then strip the leading "." character. Is that any faster? If you are
> using vim 6.0, you could use '\.\@<=[^.]\+$' instead. Another thing to try
> (which may or may not be faster) is to combine matchend('.*\.') and strpart().
> HTH --Benji Fisher
tried three different ways that you suggested but I didn't find much
difference in the time taken. Out of all four(including my original way),
matchstr(getline("."), '\.[^.]\+$') with strpart was slightly fast, but
not much to really give an edge. All the remaining showed the same
Thanks anyway for suggesting alternatives.
Do You Yahoo!?
Get your free @... address at http://mail.yahoo.com