Skip to content

Instantly share code, notes, and snippets.

@kamichidu
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save kamichidu/cd0c38b8ebea4fb5ca0d to your computer and use it in GitHub Desktop.

Select an option

Save kamichidu/cd0c38b8ebea4fb5ca0d to your computer and use it in GitHub Desktop.
" nchars => {'ntimes' => 0, 'time' => 0.0}
let g:time_required= {}
" vimproc (file) ver.
function! TryIt(fname)
let ofile= tempname()
call vimproc#system(printf('cat %s >%s', a:fname, ofile))
let start_time= reltime()
let lines= readfile(ofile)
let time= str2float(reltimestr(reltime(start_time)))
if !has_key(g:time_required, a:fname)
let g:time_required[a:fname]= {'ntimes': 0, 'time': 0.0}
endif
let g:time_required[a:fname].ntimes+= 1
let g:time_required[a:fname].time+= time
endfunction
for _ in range(1, 100)
call TryIt('./chars/100')
call TryIt('./chars/500')
call TryIt('./chars/1000')
call TryIt('./chars/2000')
call TryIt('./chars/3000')
call TryIt('./chars/4000')
call TryIt('./chars/5000')
call TryIt('./chars/10000')
call TryIt('./chars/20000')
call TryIt('./chars/30000')
call TryIt('./chars/40000')
endfor
function! s:comparator(lhs, rhs)
return str2nr(fnamemodify(a:lhs, ':t')) - str2nr(fnamemodify(a:rhs, ':t'))
endfunction
for nchars in sort(keys(g:time_required), 's:comparator')
let ntimes= g:time_required[nchars].ntimes
let time= g:time_required[nchars].time
echo printf("%s\t%f", fnamemodify(nchars, ':t'), time / ntimes)
endfor
" nchars => {'ntimes' => 0, 'time' => 0.0}
let g:time_required= {}
" process_manager版
let g:PM= vital#of('vital').import('ProcessManager')
function! TryIt(fname)
call g:PM.touch('s', 'cat ' . a:fname)
let start_time= reltime()
while 1
let [out, err, stat]= g:PM.read('s', [''])
if stat ==# 'matched'
break
endif
endwhile
let lines= split(out, "\n")
let time= str2float(reltimestr(reltime(start_time)))
call g:PM.term('s')
if !has_key(g:time_required, a:fname)
let g:time_required[a:fname]= {'ntimes': 0, 'time': 0.0}
endif
let g:time_required[a:fname].ntimes+= 1
let g:time_required[a:fname].time+= time
endfunction
for _ in range(1, 100)
call TryIt('./chars/100')
call TryIt('./chars/500')
call TryIt('./chars/1000')
call TryIt('./chars/2000')
call TryIt('./chars/3000')
call TryIt('./chars/4000')
call TryIt('./chars/5000')
call TryIt('./chars/10000')
call TryIt('./chars/20000')
call TryIt('./chars/30000')
call TryIt('./chars/40000')
endfor
function! s:comparator(lhs, rhs)
return str2nr(fnamemodify(a:lhs, ':t')) - str2nr(fnamemodify(a:rhs, ':t'))
endfunction
for nchars in sort(keys(g:time_required), 's:comparator')
let ntimes= g:time_required[nchars].ntimes
let time= g:time_required[nchars].time
echo printf("%s\t%f", fnamemodify(nchars, ':t'), time / ntimes)
endfor
" nchars => {'ntimes' => 0, 'time' => 0.0}
let g:time_required= {}
" vimproc版
function! TryIt(fname)
let proc= vimproc#popen3('cat ' . a:fname)
let start_time= reltime()
let buf= ''
while !proc.stdout.eof
let buf.= proc.stdout.read()
endwhile
let lines= split(buf, "\n")
let time= str2float(reltimestr(reltime(start_time)))
call proc.waitpid()
if !has_key(g:time_required, a:fname)
let g:time_required[a:fname]= {'ntimes': 0, 'time': 0.0}
endif
let g:time_required[a:fname].ntimes+= 1
let g:time_required[a:fname].time+= time
endfunction
for _ in range(1, 100)
call TryIt('./chars/100')
call TryIt('./chars/500')
call TryIt('./chars/1000')
call TryIt('./chars/2000')
call TryIt('./chars/3000')
call TryIt('./chars/4000')
call TryIt('./chars/5000')
call TryIt('./chars/10000')
call TryIt('./chars/20000')
call TryIt('./chars/30000')
call TryIt('./chars/40000')
endfor
function! s:comparator(lhs, rhs)
return str2nr(fnamemodify(a:lhs, ':t')) - str2nr(fnamemodify(a:rhs, ':t'))
endfunction
for nchars in sort(keys(g:time_required), 's:comparator')
let ntimes= g:time_required[nchars].ntimes
let time= g:time_required[nchars].time
echo printf("%s\t%f", fnamemodify(nchars, ':t'), time / ntimes)
endfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment