[Mono-dev] ToString() performace in Mono

Andreas Nahr ClassDevelopment at A-SoftTech.com
Mon Nov 26 13:20:36 EST 2007


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





More information about the Mono-devel-list mailing list