[Mono-dev] ToString() performace in Mono

Robert Jordan robertj at gmx.net
Fri Nov 23 09:14:09 EST 2007


Hi Paolo,

Paolo Molaro wrote:
> On 11/22/07 pablosantosluac wrote:
>> And the following results:
>>
>>> compareCompare.exe
>> val is 5999999 and time 3525
>>
>>> "c:\Archivos de programa\Mono-1.2.5.2\bin\mono.exe" compareCompare.exe
>> val is 5999999 and time 11577
> 
> Please provide also info on the cpu specs (which cpu and frequency).
> On a 2.4 GHz core 2 duo I get:
> val is 5999999 and time 4131
> 
> The profiler output is:
> prof counts: total/unmanaged: 1033/333
>     158 15.31 % NumberStore:.ctor (int)
>      82  7.95 % System.Text.StringBuilder:Append (char)
>      59  5.72 % System.NumberFormatter:FormatGeneral
> (System.NumberFormatter/NumberStore,int,System.Globalization.NumberFormatInfo,bool,bool)
>      43  4.17 % mono(GC_mark_from
>      42  4.07 % NumberStore:AppendIntegerString (int,System.Text.StringBuilder)
>      40  3.88 % (wrapper alloc) System.Object:Alloc (intptr,int)
>      39  3.78 % /lib/i686/cmov/libc.so.6(memset
>      34  3.29 % NumberStore:get_IntegerDigits ()
>      33  3.20 % System.String:memcpy4 (byte*,byte*,int)
>      32  3.10 % mono(mono_array_new_specific
>      27  2.62 % System.String:memset (byte*,int,int)
>      27  2.62 % System.Text.StringBuilder:.ctor (string,int,int,int)
>      23  2.23 % System.NumberFormatter:FormatGeneral (System.NumberFormatter/NumberStore)
> [...]
> 
> This shows what needs improvement.
> It also shows you'll see better numbers on Linux as the string
> allocation is more optimized there.
> It may be worth doing something with the byte array in NumberStore:
> ideally it should use the stringbuilder itself to store the
> number's characters, but this means quite a few changes to the code.
> The code should also likely be changed to the standard implementation of
> using divides by 10: then we could optimize that division in the jit.


When executed on MS.NET, Mono's internal NumberFormatter (the code
behind int.ToString()), is half as fast as MS.NET's int.ToString()
but still almost 3 times faster than executed on Mono.

Numbers (Intel Core Duo 2 2GHz (4MB cache), Win XP):

		ToString	NumberFormatter
				.FormatGeneral()
		
MS.NET 1.1	1406		2734
Mono 1.2.6	7750		7656

Robert




More information about the Mono-devel-list mailing list