'find ./ -name *.jpg'
我想优化上面的语句的'发现'命令。'发现'优化
在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;
}
因为我寻找文件扩展名,并希望避免正则表达式基于字符串匹配,我 '替代B =的fnmatch(STR,基础上,标志)== 0;'与以下陈述
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;
}
之后,我期望一些性能增益,但我没有看到上述变化后的任何种类的性能增益。
- 是我在做一些事情错了吗?
- 有没有更好的方法来优化'查找'以仅搜索文件扩展名?
分析后我在fnmatch上有一些更好的数字 - CPU使用率,fnmatch这个活动占用了将近16%的CPU。 我认为,我不能减少运行查找所需的总时间(正如Thomas告诉它的是更多的磁盘活动),但应该可以通过一些更多优化来降低查找的CPU使用率。 – 2009-12-17 06:19:11