[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Speeding Up This Script

Robert Love

4/25/2006 11:46:00 PM

This is my first ruby script. It does what I want but seems dead dog
slow compared to just using shell tools like "ls" and "grep". I will
expand its purpose later but for now I just want to look at all files in
a directory and identify those that have a certain CVS tag.

Please give me advice on how to speed it up using other techniques.
Thanks.

#!/home/u102k/bin/ruby -W0

target = Regexp.new('SR_048999')

Dir['*.f'].each do |zfile|
zline = `cvs log #{zfile}`.grep(target)
if zline.length != 0 then
printf("%s %s", zfile, zline)
end
end
5 Answers

Robert Klemme

4/26/2006 8:00:00 AM

0

Robert Love wrote:
> This is my first ruby script. It does what I want but seems dead dog
> slow compared to just using shell tools like "ls" and "grep". I will
> expand its purpose later but for now I just want to look at all files in
> a directory and identify those that have a certain CVS tag.
>
> Please give me advice on how to speed it up using other techniques.
> Thanks.
>
> #!/home/u102k/bin/ruby -W0
>
> target = Regexp.new('SR_048999')
>
> Dir['*.f'].each do |zfile|
> zline = `cvs log #{zfile}`.grep(target)
> if zline.length != 0 then
> printf("%s %s", zfile, zline)
> end
> end

Invoke "cvs log" only once for all files or use a CVS lib for ruby.

Kind regards

robert

Robert Love

4/26/2006 12:54:00 PM

0

In <4b8nkkF100gf9U1@individual.net> Robert Klemme wrote:
> Robert Love wrote:
>> This is my first ruby script. It does what I want but seems dead dog
>> slow compared to just using shell tools like "ls" and "grep". I will
>> expand its purpose later but for now I just want to look at all files
>> in a directory and identify those that have a certain CVS tag.
>> Please give me advice on how to speed it up using other techniques.
>> Thanks.
>>
>> #!/home/u102k/bin/ruby -W0
>>
>> target = Regexp.new('SR_048999')
>>
>> Dir['*.f'].each do |zfile|
>> zline = `cvs log #{zfile}`.grep(target)
>> if zline.length != 0 then
>> printf("%s %s", zfile, zline)
>> end
>> end
>
> Invoke "cvs log" only once for all files or use a CVS lib for ruby.
>

Do you know of such a library? Googling ruby & cvs give tons of results
but I don't see any such library. Thanks for the pointers.

Robert Klemme

4/26/2006 2:26:00 PM

0

Robert Love wrote:
> In <4b8nkkF100gf9U1@individual.net> Robert Klemme wrote:
>> Robert Love wrote:
>>> This is my first ruby script. It does what I want but seems dead dog
>>> slow compared to just using shell tools like "ls" and "grep". I will
>>> expand its purpose later but for now I just want to look at all files
>>> in a directory and identify those that have a certain CVS tag.
>>> Please give me advice on how to speed it up using other techniques.
>>> Thanks.
>>>
>>> #!/home/u102k/bin/ruby -W0
>>>
>>> target = Regexp.new('SR_048999')
>>>
>>> Dir['*.f'].each do |zfile|
>>> zline = `cvs log #{zfile}`.grep(target)
>>> if zline.length != 0 then
>>> printf("%s %s", zfile, zline)
>>> end
>>> end
>> Invoke "cvs log" only once for all files or use a CVS lib for ruby.
>>
>
> Do you know of such a library? Googling ruby & cvs give tons of results
> but I don't see any such library. Thanks for the pointers.

http://www.google.de/search?q=ruby+cvs&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-U...

second hit

RAA is also a good place to look:

http://raa.ruby-lang.org/search.rhtml?...

Cheers

robert

Hew Wolff

4/26/2006 4:13:00 PM

0

> Please give me advice on how to speed it up using other techniques.

What does the profiler point to?

Hew Wolff

Robert Love

4/28/2006 3:03:00 AM

0

In <4b8nkkF100gf9U1@individual.net> Robert Klemme wrote:
>>
>> #!/home/u102k/bin/ruby -W0
>>
>> target = Regexp.new('SR_048999')
>>
>> Dir['*.f'].each do |zfile|
>> zline = `cvs log #{zfile}`.grep(target)
>> if zline.length != 0 then
>> printf("%s %s", zfile, zline)
>> end
>> end
>
> Invoke "cvs log" only once for all files or use a CVS lib for ruby.
>

Switching to performing "cvs log" only once on all files collectivley
did speed things up but I had to do a little more parsing and grep'ing.
My example went from 6 seconds to 0.3 seconds this way. I also used `ls *.
f` instead of Ruby's Dir function.

Thanks for the advice.