Last active
February 7, 2020 02:46
-
-
Save k-takata/63b561c9b876d9e8d26fdc73438e8842 to your computer and use it in GitHub Desktop.
Benchmark of Vim's readdir()
This file contains hidden or 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! Dirlist(d = '.') | |
new | |
let start = reltime() | |
setlocal buftype=nofile | |
let list = readdir(a:d) | |
call append(line('$'), list) | |
call append(line('$'), reltimestr(reltime(start))) | |
endfunc | |
" vim: set sw=2: |
This file contains hidden or 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! Dirlist(d = '.') | |
new | |
let start = reltime() | |
setlocal buftype=nofile | |
let pwd = chdir(a:d) | |
let list = readdir('.') | |
for f in list | |
call append(line('$'), printf("%-20s", f) .. "\t" | |
\ .. printf("%-7s", getftype(f)) .. " " | |
\ .. printf("%10u", getfsize(f)) .. " " | |
\ .. strftime("%Y-%m-%d %T", getftime(f)) .. " " .. getfperm(f)) | |
endfor | |
if pwd != '' | |
call chdir(pwd) | |
endif | |
call append(line('$'), reltimestr(reltime(start))) | |
endfunc | |
" vim: set sw=2: |
This file contains hidden or 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! Dirlist(d = '.') | |
new | |
let start = reltime() | |
setlocal buftype=nofile | |
let list = readdir(a:d) | |
let idx = 0 | |
call setline(1, list) | |
func! Sub(id) closure | |
while idx < len(list) | |
let f = list[idx] | |
let p = a:d .. '/' .. f | |
call setline(idx + 1, printf("%-20s", f) .. "\t" | |
\ .. printf("%-7s", getftype(p)) .. " " | |
\ .. printf("%10u", getfsize(p)) .. " " | |
\ .. strftime("%Y-%m-%d %T", getftime(p)) .. " " .. getfperm(p)) | |
let idx += 1 | |
if idx % 200 == 0 | |
break | |
endif | |
endwhile | |
if idx == len(list) | |
call append(line('$'), reltimestr(reltime(start))) | |
else | |
call timer_start(0, funcref('Sub')) | |
endif | |
endfunc | |
call timer_start(0, funcref('Sub')) | |
endfunc | |
" vim: set sw=2: |
This file contains hidden or 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! Dirlist(d = '.') | |
new | |
let start = reltime() | |
setlocal buftype=nofile | |
let list = readdirex(a:d) | |
for l in list | |
call append(line('$'), printf("%-20s", l.name) .. "\t" | |
\ .. printf("%-7s", l.type) .. " " | |
\ .. printf("%10u", l.size) .. " " | |
\ .. strftime("%Y-%m-%d %T", l.time) .. " " .. l.perm) | |
endfor | |
call append(line('$'), reltimestr(reltime(start))) | |
endfunc | |
" vim: set sw=2: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
:call Dirlist('c:/windows/system32')