src 与构建树时间戳比较如何更快?
for n in `cd src; find . -name "*.java"; cd -`;
do a=`echo $n | cut -d '.' -f2`;
if [[ src/$a.java -nt build/$a.class ]];
then echo src/$a.java;
fi;
done
它列出了src树中的所有java文件;然后,对于每一个,它都会删除后缀“.java”(cut -d '.' -f2
因为 find .
输出以 .
为前缀>)。然后使用 -nt 来测试 src 树中的 java 文件是否比构建树中相应的类文件新;如果较新,则输出。 [javac 然后可以使用这个来只编译需要的 src 文件,而不是使用 ant
或 make
]
问题是太慢了,大约需要 275ms。如何让它更快?
或者有没有更快的方法在 bash 中做到这一点?我不知道如何使用 find
、diff
、rsync
或 make
(这不似乎自动遍历树,并且需要明确列出的源文件)。
for n in `cd src; find . -name "*.java"; cd -`;
do a=`echo $n | cut -d '.' -f2`;
if [[ src/$a.java -nt build/$a.class ]];
then echo src/$a.java;
fi;
done
It lists all the java files in the src tree; then for each one, it removes the suffix ".java" (cut -d '.' -f2
because find .
output is prefixed with .
). It then uses -nt
to test if the java file in the src tree is newer than the corresponding class file in the build tree; if it is newer, it is output. [javac can then use this to compile only the needed src files, instead of using ant
or make
]
The problem is that it is too slow, taking about 275ms. How to make it faster?
Or is there a faster way to do this in bash? I can't see how to do it with find
, diff
, rsync
nor make
(which doesn't seem to traverse trees automatically, and needs explicitly listed source files).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
try this:
我不知道这种结构是否会更快,但可能值得一试:
while
形式可能不会提供任何提升。折叠的if
可以。正则表达式可能会提供一点贡献。正如您所发现的,消除对
cut
的调用产生了最大的区别。I don't know if this structure would be any faster, but it might be worth a try:
The
while
form probably won't provide any boost. The collapsedif
may. The regex might provide a small contribution.As you've found out, eliminating a call to
cut
has made the biggest difference.ant 执行智能构建逻辑,除非修改了源代码,否则它不会构建类。
您可能还想研究 scons,它不是本机 Java 构建工具,但在编译高效的复杂构建树方面非常方便,并且也有 java 构建器。
ant performs smart building logic, it will not build a class unless the source was modified.
You might also like to look into scons which is not a native Java build tool but is very handy at compiling efficient complex build trees and does have java builder as well.
采用kon的文件名修改方法,速度平均从320ms提高到45ms。谢谢康!
原来的现在有点慢(以前是 275 毫秒;现在是 320 毫秒);我不知道为什么。我正在使用同一条线。播放视频后可能会出现不同的系统源。
编辑第一个评论:将“src/”删除,而不是
cd src;
...cd -;
。请注意,同时使用了$n
和$n2
[您不能嵌套 ${var/A/B} 构造,可以吗?]Adopting kon's approach to the filename munging, the speed improves from 320ms to 45ms on average. Thanks kon!
The original is a bit slower now (was 275ms; now 320ms); I don't know why. I'm using the same line. Maybe different system sources after playing a video.
EDIT re rst's comment: mangling the "src/" away instead of
cd src;
...cd -;
. Note that both$n
and$n2
are used [you can't nest the ${var/A/B} construct, can you?]