[Mono-dev] Performance of TextWriter.ReadToEnd()

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Tue Jul 14 20:13:20 EDT 2009


On Tue, 2009-07-14 at 18:06 -0500, Jimmy Tang wrote:
> 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)

That must be a Mono on windows issue. I tried this:
----------------
gonzalo at laptop:/tmp$ ls -l output2 output3
-rw-r--r-- 1 gonzalo gonzalo 5132004 2009-07-14 20:06 output2
-rw-r--r-- 1 gonzalo gonzalo 5888896 2009-07-14 20:07 output3
gonzalo at laptop:/tmp$ time -p mono rl.exe < output2
5132004
real 0.43
user 0.36
sys 0.05
gonzalo at laptop:/tmp$ time -p mono rl.exe < output3
5888896
real 0.41
user 0.35
sys 0.08
---------------
output2 has ~800k lines with a number.
output3 is almost the same but with everything in one single line.

-Gonzalo




More information about the Mono-devel-list mailing list