Loading ...
Sorry, an error occurred while loading the content.

Re: performance of matchstr vs. substitute

Expand Messages
  • Hari Krishna Dara
    On Mon, 29 Oct 2001 at 11:32pm, Benji Fisher wrote:Hari Krishna Dara wrote: I thought matchstr should perform better than substitute, but I was
    Message 1 of 3 , Nov 2, 2001
    • 0 Attachment
      On Mon, 29 Oct 2001 at 11:32pm, Benji Fisher wrote:

      > Hari Krishna Dara wrote:
      > >
      > > 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
      >
      >

      Ok, I finally had a chance to try the different options you have given. I
      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
      performance.

      Thanks anyway for suggesting alternatives.
      Hari


      _________________________________________________________
      Do You Yahoo!?
      Get your free @... address at http://mail.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.