Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created March 2, 2020 00:06
Show Gist options
  • Select an option

  • Save danidiaz/b12eb7d4fdc5397f56c7503579c356f3 to your computer and use it in GitHub Desktop.

Select an option

Save danidiaz/b12eb7d4fdc5397f56c7503579c356f3 to your computer and use it in GitHub Desktop.
(micro)benchmarking Vimscript closures
function Func1(x)
function! Func1Clos(y) closure
return a:x + a:y
endfunction
return funcref('Func1Clos')
endfunction
function Func2(x)
return { y -> a:x + y }
endfunction
function Func3(x)
return funcref('Func3Clos',[a:x])
endfunction
function Func3Clos(x,y)
return a:x + a:y
endfunction
function TestFunc(f,rounds)
let i = 0
let time1 = reltime()
while l:i < a:rounds
call a:f(1)(2)
let l:i+=1
endwhile
return reltime(l:time1)
endfunction
" test with
" echo reltimestr(TestFunc(funcref('Func3'),100000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment