计划表现 [英] Program Performance

查看:71
本文介绍了计划表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个程序执行以下操作:给定一个目录作为唯一参数,它进入该目录并查找其中包含2的目录特殊类型的非常大的文件。如果它找到这些文件,它会逐行查看每个文件,看它们是否包含某些字符串。如上所述,这两个文件非常大,包含大量信息,我最近在某个目录上运行了这个程序,需要35分钟才能完成。我已经尽可能地优化算法,使用二进制搜索来比较我正在寻找的每个值的每一行(不想为这个特定程序实现哈希表)。我的问题是,使用''grep''命令查找我正在寻找的信息,而不是打开每个文件并逐行进行,或者甚至会产生影响,我会更快吗?


KiSSz

Hi,

I have a program that does the following: given a directory as it''s only argument, it goes to that directory and looks for directories inside that contain 2 special types of very large files. If it finds these files, it goes through each file line by line looking to see if they contain certain strings. As mentioned, these two files are very big and contain a lot of information, and I recently ran this program on a certain directory and it took 35 minutes to complete. I''ve optimized the algorithms as much as I can using binary search to compare each line for each value that I''m looking for (don''t want to implement a hash table for this particular program). My question is this, would it be faster for me to use the ''grep'' command to look for the information im looking for, rather than opening each file and going line by line, or would it even make a difference?

KiSSz

推荐答案

你是什么意思使用二进制搜索?
what do you mean by "using binary search"?


我有一个我在大文件中搜索的项目列表,它们存储在一个数组中并进行排序。二进制搜索是指您首先查看中间值以与您正在查找的值进行比较,然后如果它更少,则转到数组左半部分的中间值,如果它更大你去了数组右半部分的中间值,你继续这样做,直到找到值。通过每次比较,您可以消除一半的值,因此它比从数组的开头到结尾搜索要快得多。
I have a list of items that I''m searching for in the big files and they are stored in an array and they are sorted. A binary search is when you first look at the middle value to compare with the value you''re looking for, then if it''s less you go to middle value of the left half of the array, if it''s greater you go to the middle value of the right half of the array and you keep doing this till you find the value. With each comparison you eliminate half the values so it''s much faster than searching from the beginning of the array to the end.


我建​​议做一个基准测试。然后比较时间,看看哪一个更快。


- 凯文
I would suggest that do a Benchmark using each method (binary search and grep). Then compare the times and see which one is quicker.

--Kevin


这篇关于计划表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆