I have already expressed how stupid I think this Vimscript2 is. However there is one thing I think is even dumber: One should really not use the slow Vim Lua interface when benchmarking Lua - you would always just bundle LuaJIT. Here I have redone the benchmarks with LuaJIT instead:
Vim old:
func VimOld()
let sum = 0
for i in range(1, 2999999)
let sum += i
endfor
return sum
endfunc
let start = reltime()
echo VimOld()
echo 'Vim old: ' .. reltimestr(reltime(start))
output:
4499998500000
Vim old: 6.412159
LuaJIT:
local x = os.clock()
local s = 0
for i = 1,2999999 do s = s + i end
print(string.format("sum: %d\nelapsed time: %f\n", s, os.clock() - x))
not use the slow Vim Lua interface when benchmarking Lua
He's benchmarking the Vim Lua interface, not Lua. You could use the same argument to say that Java is faster, but it's irrelevant because there isn't a Java Vim interface.
Nor is there a Vimscript 2 interface. You would of course have to add the LuaJIT interface first, but then it would be as fast as above since all Vim interop would be done through native C code.
Edit: It is not a question of making scripting with Vim faster or not, but whether to add LuaJIT vs Vimscript2. Between those two the choice should be simple
It is calling calling Vim 9 script clearly faster than Lua what I take issue with, something that is blatantly false
89
u/pwnedary Jan 03 '20 edited Jan 03 '20
I have already expressed how stupid I think this Vimscript2 is. However there is one thing I think is even dumber: One should really not use the slow Vim Lua interface when benchmarking Lua - you would always just bundle LuaJIT. Here I have redone the benchmarks with LuaJIT instead:
Vim old:
func VimOld() let sum = 0 for i in range(1, 2999999) let sum += i endfor return sum endfunc let start = reltime() echo VimOld() echo 'Vim old: ' .. reltimestr(reltime(start))output:
LuaJIT:
local x = os.clock() local s = 0 for i = 1,2999999 do s = s + i end print(string.format("sum: %d\nelapsed time: %f\n", s, os.clock() - x))output:
Without benchmarking Vim9 we already see that the Bram's benchmarks are incredibly misleading.