Created
January 17, 2012 21:51
-
-
Save nukino/1629159 to your computer and use it in GitHub Desktop.
[20120118-0651]test3.vim/関数呼び出しコスト調査
This file contains 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
func! s:fact1(val) | |
if ( a:val == 1 ) | |
return 1 | |
else | |
return a:val * s:fact1(a:val-1) | |
endif | |
endfunc | |
func! s:fact2(val) | |
let i = a:val - 1 | |
let fact = a:val | |
while ( i > 0 ) | |
let fact = fact * i | |
let i -= 1 | |
endwhile | |
return fact | |
endfunc | |
func! TestFunction() | |
let loopcnt = 200000 | |
let st_time = reltime() | |
let i = 0 | |
while i < loopcnt | |
call s:fact1(10) | |
let i += 1 | |
endwhile | |
echo "s:fact1->" . split(reltimestr(reltime(st_time)))[0] | |
let st_time = reltime() | |
let i = 0 | |
while i < loopcnt | |
call s:fact2(10) | |
let i += 1 | |
endwhile | |
echo "s:fact2->" . split(reltimestr(reltime(st_time)))[0] | |
endfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment