[英]'find' optimization
'find ./ -name *.jpg'
I am trying to optimize 'find' command for the above statement. 我正在尝试为上述语句优化“查找”命令。
method which handle the '-name' predicate in find implementation. 在find实现中处理“ -name”谓词的方法。
static boolean
pred__name __common (const char *pathname, const char *str, int flags)
{
boolean b;
char *base = base_name (pathname);
strip__trailing __slashes(base);
b = fnmatch (str, base, flags) == 0;
free (base);
return b;
}
since I am looking for file extensions and want to avoid the regular expression based string matching, I replaced 'b = fnmatch (str, base, flags) == 0;' 因为我正在寻找文件扩展名,并且想避免基于正则表达式的字符串匹配,所以我替换了“ b = fnmatch(str,base,flags)== 0;”。 with following statements
以下陈述
int strLen = strlen(base);
b = FNM_NOMATCH;
if (strLen>=4 && (str[3] == base[strLen]) &&
(str[2] == base[strLen -1]) && (str[1] ==
base[strLen-2]) && (str[0] == base[strLen-3]))
{
b = 0;
}
After this I expected some performance gain, but I don't see any kind of performance gain after the above change. 在此之后,我希望获得一些性能提升,但是在进行上述更改之后,我看不到任何性能提升。
I doubt that the regex matching is the bottleneck. 我怀疑正则表达式匹配是否是瓶颈。 Since
find
traverses the filesystem, the overhead is probably in disk seek times, and in case of an in-memory filesystem, in system calls and the resulting context switches. 由于
find
遍历文件系统,因此开销可能在磁盘查找时间中,而在内存文件系统中,则在系统调用和结果上下文切换中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.