[Mono-dev] ToString() performace in Mono revisited
Eyal Alaluf
eyala at mainsoft.com
Thu Dec 27 11:21:03 EST 2007
With the attchments zipped to reduce size.
________________________________
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Eyal
Alaluf
Sent: 27 December 2007 17:28
To: mono-devel-list at lists.ximian.com
Cc: Miguel de Icaza
Subject: [Mono-dev] ToString() performace in Mono revisited
I got complaints that the font color within the table is white so this
is a resent :-)
Hi, all.
Attached is a redesigned implementation of the NumberFormatter class.
The patch includes a new algorithm for float and double ToString
implementation that improves performance by a factor of 25(!) and upto
440(!!!). The patch includes further improvements to integer ToString as
well as Andreas suggestion of avoiding calling
NumberFormatInfo.CurrentInfo in the case of integer types default
ToString() implementation.
This patch should improve Mono's performance in important use cases such
as web-services where primitive ToString performance is an important
factor.
The following is a table showing the improvements for the different
primitive types using the patch. All the results are in milliseconds and
for a run of 10,000,000 iterations with warm-up of 10,000,000 iterations
as well.
Mono 1.2.6
Patch
Improvement
12345.ToString("G")
10079
7328
1.37
12345L.ToString("G")
13203
7297
1.81
0.12345.ToString("G")
323750
13047
24.8(!)
1.2345E-200.ToString("G")
6376500
14328
445(!!!)
0.12345m.ToString("G")
51078
9875
5.2
12345.ToString()
12406/7781
5687
2.2/1.37
12345L.ToString()
15703/11016
5750
2.7/1.9
Note that for Mono 1.2.6 12345.ToString() there are two numbers - the
first is Mono 1.2.6 version (which is slower then 12345.ToString("G")!)
and the second is after applying Andreas suggestion on top of Mono
1.2.6.
The following are the results of the new algorithm compared to the old
Mono algorithm and the .Net 2.0 native ToString performance, all three
running on Microsoft .Net 2.0. The results show that the new code
matches and even out-performs .Net ToString implementation.
Mono 1.2.6 algorithm
Microsoft .Net 2.0
New Patch algorithm
Improvement over Mono 1.2.6
Improvement over .Net 2.0
12345.ToString("G")
3700
2291
1827
2.0
1.25
12345L.ToString("G")
4559
2242
1919
2.38
1.17
0.12345.ToString("G")
281090
4006
3897
72.1(!!)
1.03
1.2345E-200.ToString("G")
5686000
4634
4613
1233(!!!)
1.00
0.12345m.ToString("G")
14562
3095
2294
6.3
1.35
12345.ToString()
3900/3002
2344
1313
3.0/2.3
1.79
12345L.ToString()
4684/3823
2245
1383
3.4/2.8
1.62
It should be noted that the new code performance improvement are even
more visible on top of .Net.
It should also be noted that .Net runs the same algorithm 4 times faster
then Mono. Since this code is self contained and almost completely
algorithmic - I believe that it may serve as a good practical test case
for improving Mono's JIT.
The redesign is composed of three main changes
* An O(1) arithmetic transformation of a double (composed of sign,
2's exponent and mantissa bits) to sign, long and 10's exponent.
* Using a character array instead of a string buffer to construct
the string result.
* Representing the number digits using hexadecimal values. That is
12345 will be represented by 0x12345.
The patch passes Mono's unit tests on both 1.1 and 2.0.
Please review and provide us with your feedback as soon as possible.
Sasha, Roei & Eyal.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071227/ac313881/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NumberFormatter.zip
Type: application/x-zip-compressed
Size: 12370 bytes
Desc: NumberFormatter.zip
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071227/ac313881/attachment.bin
More information about the Mono-devel-list
mailing list