On 4/28/06, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
Yakov Lerner wrote:
> > How much extra time does it take to read the marks from the .viminfo
> > file?
>
> There are 1358 files in $VIMRUNTIME (vim7f).
> Executint this with no :au commands (vim -u NONE)
> TIM vimgrep klslkjljklkj $VIMRUNTIME/**
> takes 46 sec.
> Executing ':rv' 1358 times takes 2 sec.
That's not the same. ":rv" reads the whole viminfo file, while reading
it for marks only does a small part of the work. My experience is that
expanding file names (e.g., for marks) takes most of the time, I guess
that will be skipped. It's difficult to think of a way to measure this.
2 out of 46 seconds is not that much anyway.
> P.S.
> command! -nargs=* -range TIMING :<count>call TIMING(<q-args>)
>
> function! TIMING(args) range
> let start=reltime()
> exe a:args
> echo "Execution took " . reltimestr(reltime(start))." sec."
> endfu
From two experiments below, it follows that vimgrep time
is dominated (75-99%) by some overhead of file opening, while
while searching is small fraction of [current] vimgrep time (1-15%)
Here are two experiments by which I tried to tell apart
two parts of vimgrep,
(1) the pattern searching part without file opening part
(2) the files opening without pattern searching
1. To test searching times separately from file loading time, I did this:
- I computed average file size under $VIMRUNTIME. It's
find . -type f | wc -l => 1274
cat `find . -type f ` | wc -c => 17,921,393
17,921,393 bytes / 1274 files = 14067 bytes.
- I created file of [approximately] average size:
perl -e 'for($k=0; $k<194;$k++) {print "x" x 72,"\n"; }' >xxx
- vim -u NONE xxx
:TIM let x=0|wh x<1274|call search('patern','w')|let x=x+1|endw
I found that search is fast, takes 1-15% of vimgrep time.
Depending on pattern, search time (1274 times) ranged from 0.31sec (!)
to 7.4 sec.
This is small part of 46 sec of vimgrep through $VIMRUNTIME/**
(my machine is retarded, 800MHZ)
The search time greately depends on pattern (filesize is 14kb).
If pattern is 'a' (NB: file consists of all 'x'), then total search time is
0.31 sec ! (that's 1274 times!). If pattern is 'xxxj' then search time
is 7.4 sec.
This is small part of 46 sec of vimgrep.
2. To test file opening time separately from pattern searching time,
I created copy of $VIMRUNTIME, but with all files empty (see script
populate.sh below). vimgrep through this tree took 29 sec:
% sh populate.sh
% vim -u NONE
:TIM vimgrep aklsjlakj /tmp/aaa/
3. Note that 29+(1..7) sec is still not 46. I speculate that remaining
10-15 sec is file contents loading time. (Note that file loading time
does not happen neither in (1) nor in (2)).
Yakov
--------------------- populate.sh script ----------------------
#!/bin/sh
# create 1274 zero-length files under /tmp/aaa
rm -rf /tmp/aaa
cd `vimruntime` || exit 1
mkdir /tmp/aaa
cp -r * /tmp/aaa
find /tmp/aaa -type f | while read x ; do
cp /dev/null $x;
done
-----------------------------------------------------------------