我绝对是ruby的新手(并使用1.9.1),所以任何帮助都表示赞赏.我所学到的关于Ruby的一切都来自谷歌.我正在尝试比较两个哈希数组,并且由于它们的大小,它已经让位于长时间并且因内存耗尽而调情.任何帮助,将不胜感激.
我有一个Class(ParseCSV),有多种方法(初始化,打开,比较,剥离,输出).我现在使用它的方式如下(这确实通过了我编写的测试,只使用了更小的数据集):
file1 = ParseCSV.new(“some_file”)
file2 = ParseCSV.new(“some_other_file”)
file1.open #this reads the file contents into an Array of Hash’s through the CSV library
file1.strip #This is just removing extra hash’s from each array index. So normally there are fifty hash’s in each array index, this is just done to help reduce memory consumption.
file2.open
file2.compare(“file1.storage”) #@storage is The array of hash’s from the open method
file2.output
Run Code Online (Sandbox Code Playgroud)
现在我正在努力的是比较方法.处理较小的数据集根本不是什么大问题,工作得足够快.然而,在这种情况下,我将大约400,000条记录(全部读入哈希数组)与具有大约450,000条记录的记录进行比较.我正试着加快速度.另外,我无法在file2上运行strip方法.我现在就是这样做的:
def compare(x)
#obviously just a verbose message
puts "Comparing and leaving behind non …Run Code Online (Sandbox Code Playgroud)