Guest User

Untitled

a guest
May 27th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. " performance comparison of 'with function' and 'without function'
  2.  
  3. function! s:Function1(i)
  4. return a:i % 2 == 0 ? 'even' : 'odd'
  5. endfunction
  6.  
  7. function! s:Function2(i)
  8. if a:i % 2 == 0
  9. return 'even'
  10. else
  11. return 'odd'
  12. endif
  13. endfunction
  14.  
  15. function! s:Main()
  16. let max = 1000000
  17.  
  18. " without function
  19. let i = 0
  20. let start = reltime()
  21. while i < max
  22. let hoge = i % 2 == 0 ? 'even' : 'odd'
  23. let i += 1
  24. endwhile
  25. echo 'without function : ' . reltimestr(reltime(start))
  26.  
  27. " with function 1
  28. let i = 0
  29. let start = reltime()
  30. while i < max
  31. let hoge = <SID>Function1(i)
  32. let i += 1
  33. endwhile
  34. echo 'with function1 : ' . reltimestr(reltime(start))
  35.  
  36. " with function 2
  37. let i = 0
  38. let start = reltime()
  39. while i < max
  40. let hoge = <SID>Function2(i)
  41. let i += 1
  42. endwhile
  43. echo 'with function2 : ' . reltimestr(reltime(start))
  44. endfunction
  45.  
  46. execute <SID>Main()
Add Comment
Please, Sign In to add comment