Skip to content

Instantly share code, notes, and snippets.

@nukino
Created January 17, 2012 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nukino/1629159 to your computer and use it in GitHub Desktop.
Save nukino/1629159 to your computer and use it in GitHub Desktop.
[20120118-0651]test3.vim/関数呼び出しコスト調査
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