Reply to message «Re: map copy and split v:val», sent 11:09:31 14 November 2010, Sunday by epanda:
> > map(list1, 'v:val."*".list2[index(list1,v:val)]')
>
> Ok this is perfect. It works like excel and faster I think...ust for
> adding operations for the moment.
>
> Thank you a lot Israel.
No, that is a very bad solution: v:val may be contained in the list1 more then
once and there is a huge impact on perfomance: `index(list1, v:val)' iterates
over list1 until it finds v:val, but it can be replaced with just v:key which
does not do any iterations and does not require all elements to be unique. Here
is the benchmark:
(zyx:tmp/vim/test-joinlists) % cat 1.vim
let list1=range(1, 50000)
let list2=copy(list1)
call map(list1, 'v:val."*".list2[index(list1, v:val)]')
(zyx:tmp/vim/test-joinlists) % cat 2.vim
let list1=range(1, 50000)
let list2=copy(list1)
let i=0
let llist=len(list1)
while i<llist
let list1.='*'.list2[i]
let i+=1
endwhile
(zyx:tmp/vim/test-joinlists) % cat 3.vim
let list1=range(1, 50000)
let list2=copy(list1)
call map(list1, 'v:val."*".list2[v:key]')
(zyx:tmp/vim/test-joinlists) % cat 4.vim
let list1=range(1, 50000)
let list2=copy(list1)
for i in range(0, len(list1)-1)
let list1[i].="*".list2[i]
endfor
(zyx:tmp/vim/test-joinlists) % for f in *.vim ; do time vim -u NONE -c 'set
nocompatible' -c "execute 'source '.fnameescape(${(qqq)f})" -c 'qa!' ; done
vim -u NONE -c 'set nocompatible' -c -c 'qa!' 8,27s user 0,01s system 99% cpu
8,287 total
vim -u NONE -c 'set nocompatible' -c -c 'qa!' 0,02s user 0,01s system 96% cpu
0,037 total
vim -u NONE -c 'set nocompatible' -c -c 'qa!' 0,17s user 0,01s system 98% cpu
0,182 total
vim -u NONE -c 'set nocompatible' -c -c 'qa!' 0,26s user 0,01s system 99% cpu
0,281 total
You see: while loop is the fastest solution, map() with v:key is slightly
slower
and solution with index is 50 times slower then map+v:key.
signature.asc
Description: This is a digitally signed message part.
