Skip to content

Instantly share code, notes, and snippets.

@machakann
Created February 11, 2020 09:57
Show Gist options
  • Save machakann/2c5e21eab2957c3d54a9ac951fc2ec4b to your computer and use it in GitHub Desktop.
Save machakann/2c5e21eab2957c3d54a9ac951fc2ec4b to your computer and use it in GitHub Desktop.
The script to profile osa_filter() function in asyncomplete-ezfilter.vim
function! Tic(...)
if a:0 > 0 && !empty(a:1)
if exists(':PP') == 2
PP! a:1
else
echomsg string(a:1)
endif
endif
let s:starttime = reltime()
endfunction
function! Toc()
return reltimestr(reltime(s:starttime))
endfunction
command! -nargs=? Tic call Tic(<args>)
command! -nargs=0 Toc echomsg Toc()
command! -nargs=1 Time call Tic() | execute <q-args> | echomsg printf('%s seconds: %s', Toc(), <q-args>)
function! s:randstr(n, ...) abort
let l:availchar = get(a:000, 0, 'abcdefghijklmnopqrstuvwxyz')
let l:indmax = len(l:availchar)
return join(map(range(a:n), 'l:availchar[rand() % l:indmax]'), '')
endfunction
let s:seed = srand(1)
let s:number_of_words = 1000
let s:length_of_word = 20
let s:threshold = s:length_of_word - 3
let s:items = map(range(s:number_of_words), '{"word": s:randstr(s:length_of_word)}')
let s:base = s:randstr(s:length_of_word)
let s:ezfilter = asyncomplete#preprocessor#ezfilter#_obj(s:base)
Time call s:ezfilter.osa_filter(s:items, s:threshold)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment