Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " performance comparison of 'with function' and 'without function'
- function! s:Function1(i)
- return a:i % 2 == 0 ? 'even' : 'odd'
- endfunction
- function! s:Function2(i)
- if a:i % 2 == 0
- return 'even'
- else
- return 'odd'
- endif
- endfunction
- function! s:Main()
- let max = 1000000
- " without function
- let i = 0
- let start = reltime()
- while i < max
- let hoge = i % 2 == 0 ? 'even' : 'odd'
- let i += 1
- endwhile
- echo 'without function : ' . reltimestr(reltime(start))
- " with function 1
- let i = 0
- let start = reltime()
- while i < max
- let hoge = <SID>Function1(i)
- let i += 1
- endwhile
- echo 'with function1 : ' . reltimestr(reltime(start))
- " with function 2
- let i = 0
- let start = reltime()
- while i < max
- let hoge = <SID>Function2(i)
- let i += 1
- endwhile
- echo 'with function2 : ' . reltimestr(reltime(start))
- endfunction
- execute <SID>Main()
Add Comment
Please, Sign In to add comment