Skip to content

Instantly share code, notes, and snippets.

@k-takata
Last active December 22, 2017 03:45
Show Gist options
  • Save k-takata/7a692bceed281fce23e56d4d179c52b7 to your computer and use it in GitHub Desktop.
Save k-takata/7a692bceed281fce23e56d4d179c52b7 to your computer and use it in GitHub Desktop.
" See: https://github.com/vim-jp/vital.vim/pull/564
" Execute with: vim -S is_comp.vim
profile start is_comp_prof.log
profile func Is_comparable*
profile func Main
let s:types = {
\ 'number': 0,
\ 'string': 1,
\ 'func': 2,
\ 'list': 3,
\ 'dict': 4,
\ 'float': 5,
\ 'bool': 6,
\ 'none': 7,
\ 'job': 8,
\ 'channel': 9,
\ }
lockvar 1 s:types
let s:type_names = {
\ '0': 'number',
\ '1': 'string',
\ '2': 'func',
\ '3': 'list',
\ '4': 'dict',
\ '5': 'float',
\ '6': 'bool',
\ '7': 'none',
\ '8': 'job',
\ '9': 'channel',
\ }
lockvar 1 s:type_names
function! Is_comparable1(value1, value2) abort
let [t1, t2] = sort([type(a:value1), type(a:value2)])
let tname1 = s:type_names[t1]
let tname2 = s:type_names[t2]
if tname1 ==# 'list' || tname1 ==# 'dict' ||
\ tname2 ==# 'list' || tname2 ==# 'dict'
return tname1 ==# tname2
endif
if (tname2 ==# 'job' || tname2 ==# 'channel') &&
\ (tname1 ==# 'number' || tname1 ==# 'float')
return 0
endif
return 1
endfunction
function! Is_comparable2(value1, value2) abort
try
let _ = a:value1 ==# a:value2
return 1
catch
return 0
endtry
endfunction
function! Main()
let l1 = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
let l2 = copy(l1)
call Is_comparable1(l1, l2)
call Is_comparable2(l1, l2)
call Is_comparable1([], [])
call Is_comparable2([], [])
call Is_comparable1([], {})
call Is_comparable2([], {})
call Is_comparable1({}, [])
call Is_comparable2({}, [])
call Is_comparable1({}, {})
call Is_comparable2({}, {})
call Is_comparable1(1, [])
call Is_comparable2(1, [])
endfunction
call Main()
quit
FUNCTION Main()
Called 1 time
Total time: 0.000348
Self time: 0.000101
count total (s) self (s)
1 0.000028 let l1 = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
1 0.000011 let l2 = copy(l1)
1 0.000038 0.000014 call Is_comparable1(l1, l2)
1 0.000019 0.000009 call Is_comparable2(l1, l2)
1 0.000019 0.000005 call Is_comparable1([], [])
1 0.000009 0.000002 call Is_comparable2([], [])
1 0.000018 0.000005 call Is_comparable1([], {})
1 0.000060 0.000002 call Is_comparable2([], {})
1 0.000018 0.000004 call Is_comparable1({}, [])
1 0.000040 0.000003 call Is_comparable2({}, [])
1 0.000018 0.000003 call Is_comparable1({}, {})
1 0.000010 0.000003 call Is_comparable2({}, {})
1 0.000020 0.000006 call Is_comparable1(1, [])
1 0.000037 0.000003 call Is_comparable2(1, [])
FUNCTION Is_comparable1()
Called 6 times
Total time: 0.000094
Self time: 0.000094
count total (s) self (s)
6 0.000039 let [t1, t2] = sort([type(a:value1), type(a:value2)])
6 0.000014 let tname1 = s:type_names[t1]
6 0.000011 let tname2 = s:type_names[t2]
6 0.000015 if tname1 ==# 'list' || tname1 ==# 'dict' || tname2 ==# 'list' || tname2 ==# 'dict'
6 0.000011 return tname1 ==# tname2
endif
if (tname2 ==# 'job' || tname2 ==# 'channel') && (tname1 ==# 'number' || tname1 ==# 'float')
return 0
endif
return 1
FUNCTION Is_comparable2()
Called 6 times
Total time: 0.000153
Self time: 0.000153
count total (s) self (s)
6 0.000005 try
6 0.000059 let _ = a:value1 ==# a:value2
3 0.000004 return 1
catch
3 0.000007 return 0
endtry
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
1 0.000348 0.000101 Main()
6 0.000153 Is_comparable2()
6 0.000094 Is_comparable1()
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
6 0.000153 Is_comparable2()
1 0.000348 0.000101 Main()
6 0.000094 Is_comparable1()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment