I have created a repository for the Vim9 script experiments:
https://github.com/brammool/vim9
I did another measurement for a more realistic example, re-indenting a
large number of lines. In old Vim script it would be:
let totallen = 0
for i in range(1, 100000)
call setline(i, ' ' .. getline(i))
let totallen += len(getline(i))
endfor
The timing differences are much smaller than for the computational
example, but Vim9 script is clearly the fastest:
Vim old: 0.853752
Python: 0.304584
Lua: 0.286573
Vim new: 0.190276
Compared to legacy Vim script it is a 4 times faster.
If you want to look at the instructions that are used internally, the
":disassemble" command shows what's the compilation result. For
example, this function:
def VimNew(): number
let totallen = 0
for i in range(1, 100000)
setline(i, ' ' .. getline(i))
totallen += len(getline(i))
}
return totallen
enddef
Results in this:
let totallen = 0
0 STORE 0 in $0
for i in range(1, 100000)
1 STORE -1 in $1
2 PUSHNR 1
3 PUSHNR 100000
4 BCALL range(argc 2)
5 FOR $1 -> 21
6 STORE $2
setline(i, ' ' .. getline(i))
7 LOAD $2
8 PUSHS " "
9 LOAD $2
10 BCALL getline(argc 1)
11 CONCAT
12 BCALL setline(argc 2)
13 DROP
totallen += len(getline(i))
14 LOAD $0
15 LOAD $2
16 BCALL getline(argc 1)
17 BCALL len(argc 1)
18 ADDNR
19 STORE $0
}
20 JUMP -> 5
21 DROP
return totallen
22 LOAD $0
23 RETURN
Obviously there is still an awful lot of work to be done. Fortunately,
the numbers show it's worth it.
--
The Law of VIM:
For each member b of the possible behaviour space B of program P, there exists
a finite time t before which at least one user u in the total user space U of
program P will request b becomes a member of the allowed behaviour space B'
(B' <= B).
In other words: Sooner or later everyone wants everything as an option.
-- Vince Negri
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202001021944.002Ji2HT017623%40masaka.moolenaar.net.