[Mono-dev] Performance of TextWriter.ReadToEnd()
Jimmy Tang
talyian at gmail.com
Tue Jul 14 19:06:29 EDT 2009
I'm playing around with some of the language shootout game benchmarks
at http://shootout.alioth.debian.org,
and I noticed a striking performance issue;
I'm testing on mono 2.4 build 6 / vista64 vs .NET 3.5 sp1. Test code:
static void Main() {
var sequence = Console.In.ReadToEnd();
Console.WriteLine(sequence.Length);
}
test input is a 50MB file.
results.
$ time ./test.exe < ../fasta5M.in.txt
real 0m1.352s
user 0m0.015s
sys 0m0.000s
$ time mono test.exe < ../fasta5M.in.txt
real 0m18.154s
user 0m0.015s
sys 0m0.000s
I see the ReadToEnd() is implemented along the lines of
char[] buffer;
while(Read(buffer) > 0)
stringbuilder.append(buffer)
Just as a rudimentarytest using a temp string instead of char[]:
string buffer;
while((buffer = ReadLine()) != null)
stringbuilder.Append(buffer)
is much faster (~10x, similar to the .NET performance), but I'd
imagine this generates more garbage.
not being familiar with the mono codebase, I wasn't sure if the
problem was with StreamReader.Read(char[],int,int) or with
StringBuilder.Append(char[],int,int).
Can anyone shed some insight on this problem?
More information about the Mono-devel-list
mailing list