I have a class which holds data while it's being manipulated. The
trouble is that I call to_s() quite a few times printing the resulting
data to a file. This increases the run time of the script a surprising
amount raising the runtime from about 6 minutes to about 8 and a half.
The code looks roughly likely the following,
class Example
.
.
def to_s
sout << "a=#{@a}"
sout << "b=#{@b}"
sout.join("\n")
end
end
# in main
File.open(outfile,File::CREAT|File::RDWR|File::APPEND) do |fp|
the_data.each do |d|
fp.puts d
fp.puts # add blank line
end
end
Anyone care to suggest a way to speed this up? Is it faster to
sout << "a=" + @a
instead of
sout << "a=#{@a}"
Jeff.