Closed lacygoill closed 4 years ago
As a simple test, we can use this command to test how faster lambdas are compared to eval strings once they're compiled inside a :def
function:
vim -es -Nu NONE -i NONE -U NONE -S <(cat <<'EOF'
vim9script
def Lambda()
var time = reltime()
range(999999)->map({_, v-> v + 1})
setline(1, reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run lambdas')
enddef
Lambda()
def EvalString()
var time = reltime()
range(999999)->map('v:val + 1')
setline(2, reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run eval strings')
enddef
EvalString()
:%p
qa!
EOF
)
As the title suggests, lambdas are faster than eval strings inside a
:def
function. I think that's because they're compiled, while eval strings are not.