Created
March 2, 2020 00:06
-
-
Save danidiaz/b12eb7d4fdc5397f56c7503579c356f3 to your computer and use it in GitHub Desktop.
(micro)benchmarking Vimscript closures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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