很慢dir() [英] Very slow dir()
问题描述
当有很多文件时,大约4000, dir()
函数很慢。我的猜测是创建一个结构并以低效的方式填写这些值。
When there are many files, around 4000, dir()
function is very slow. My guess is it creates a structure and filling in the values in an inefficient way.
使用 dir()是否有任何快捷优雅的选择,
?
更新:使用MATLAB R2011a在64位,Windows 7中测试。
Update: Testing it in 64 Bit, Windows 7 with MATLAB R2011a.
更新2:完成大约需要2秒钟。
Update 2: It takes around 2 seconds to complete.
推荐答案
您正在使用哪个CPU /操作系统?我刚刚在我的机器上尝试了一个带有5000个文件的目录,它很快:
Which CPU / OS are you using? I just tried it on my machine with a directory with 5000 files and it's pretty quick:
>> d=dir;
>> tic; d=dir; toc;
Elapsed time is 0.062197 seconds.
>> tic; d=ls; toc;
Elapsed time is 0.139762 seconds.
>> tic; d=dir; toc;
Elapsed time is 0.058590 seconds.
>> tic; d=ls; toc;
Elapsed time is 0.063663 seconds.
>> length(d)
ans =
5002
MATLAB的ls和dir函数的另一个替代方法是在MATLAB中直接使用Java的 java.io.File
:
The other alternative to MATLAB's ls and dir functions is to directly use Java's java.io.File
in MATLAB:
>> f0=java.io.File('.');
>> tic; x=f0.listFiles(); toc;
Elapsed time is 0.006441 seconds.
>> length(x)
ans =
5000
这篇关于很慢dir()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!