[Mono-dev] ToString() performace in Mono

Andreas Nahr ClassDevelopment at A-SoftTech.com
Tue Nov 27 18:26:06 EST 2007


Forgot to post some numbers about memory use (1000000 iterations):

New:
29MB StringBuilder
23MB NumberFormatter
21MB Byte[]
=
73MB Total

Old:
76MB StringBuilder
25MB Strings
23MB NumberFormatter
21MB Byte[]
=
146MB Total

So nearly exactly 50% saved Memory allocations ;) 

Greetings
Andreas

-----Ursprüngliche Nachricht-----
Von: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] Im Auftrag von Andreas
Nahr
Gesendet: Montag, 26. November 2007 19:21
An: 'Kazuki Oikawa'; 'pablosantosluac'
Cc: mono-devel-list at lists.ximian.com
Betreff: Re: [Mono-dev] ToString() performace in Mono

The following code (add to NumberFormatter) and redirect the ToStrings
improves performance even more:

Old Formatter: 1266
New Formatter with negative number: 953
New Formatter with positive number: 750

Tested on Windows XP, Mono 1.2.5

		internal static string FormatInteger (ref NumberStore ns)
		{
			// Add one additional char for default sign, one for
potential 0-padding
			StringBuilder cb = new StringBuilder
(ns.IntegerDigits + 2);

			if (!ns.Positive && !ns.CheckZeroOnlyInteger ())
				cb.Append
(NumberFormatInfo.CurrentInfo.NegativeSign);

			ns.AppendIntegerString (ns.IntegerDigits > 0 ?
ns.IntegerDigits : 1, cb);
			return cb.ToString ();
		}

The additional performance in Comparison to Kazuki Oikawa suggestion is
mainly gained through not retrieving NumberFormatInfo.CurrentInfo in cases
where it's not needed (and other small things like ref struct).
NumberFormatInfo.CurrentInfo should be optimized anyways. It just shouldn't
be as slow as it is as it is likely used in other situations, too.

Greetings
Andreas

-----Ursprüngliche Nachricht-----
Von: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] Im Auftrag von Kazuki
Oikawa
Gesendet: Samstag, 24. November 2007 06:02
An: pablosantosluac
Cc: mono-devel-list at lists.ximian.com
Betreff: Re: [Mono-dev] ToString() performace in Mono

Hi.

This patch improves ToString performance (30% faster).

Running on Opteron 270 (2GHz), Gentoo Linux 2007.0 x86_64 $ mono hoge.exe
val is 5999999 and time 7008 (before) $ mono hoge.exe val is 5999999 and
time 5078 (after)

Current code is use "G" format but this equals "D" format when precision is
not defined and value is integer.

Best regards.

--
Kazuki Oikawa


_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list





More information about the Mono-devel-list mailing list