[Mono-dev] ToString() performace in Mono
pablosantosluac
pablosantosluac at terra.es
Thu Nov 22 11:26:19 EST 2007
well, we tried but it doesn't get a big speed up... just about 2 to 5%
----- Original Message -----
From: Alan McGovern
To: Petit Eric
Cc: pablosantosluac ; mono-devel-list at lists.ximian.com
Sent: Thursday, November 22, 2007 3:23 PM
Subject: Re: [Mono-dev] ToString() performace in Mono
StringBuilder is only faster if you're concatenating a lot of variables. In this case, there's no benefit to using stringbuilder. If he was concatenating all the numbers from i=0->1000, then yes, a stringbuilder would be better.
It might be worth cracking out a profiler and seeing where the time is spent.
As NumberStore is a struct, you would get a performance boost if it was passed by ref as opposed to be value. I'd guesstimate that it'd be at least a double digit increase (> 10%). If someone has the time to modify their mono checkout to change the Int32.ToString() codepath to pass the NumberStore by ref all the way through, let me know what the performance diff is.
It should only take about 10 mins of hacking to do the change. If the boost is significant enough, maybe a patch would be accepted into mono to do this.
Alan.
On Nov 22, 2007 11:26 AM, Petit Eric <surfzoid at gmail.com> wrote:
2007/11/22, pablosantosluac <pablosantosluac at terra.es>:
> Hi,
>
> Ok, but I'm not doing string "concat" but just converting to string, and
> using StringBuilder in this scenario, it isn't faster, as you have just
> pointed to...
yes complety right, but the first idea was about the fact for string
performance, stringbuilder is fastest, but aparently not at the
instance time, only to append a long text.
oki
now we are fixed lol
>
> My point is that ToString is about 3 times slower in Mono than its .NET
> counterpart. We'll try to get rid of it as much as we can, but some
> optimization would be really great.
>
> Thanks,
>
> pablo
>
>
> ----- Original Message -----
> From: "Petit Eric" < surfzoid at gmail.com>
> To: "pablosantosluac" <pablosantosluac at terra.es>
> Cc: <mono-devel-list at lists.ximian.com >
> Sent: Thursday, November 22, 2007 11:56 AM
> Subject: Re: [Mono-dev] ToString() performace in Mono
>
>
> > Windows and String
> > val is 5999999 and time 4391
> >
> > Windows and StringBuilder
> > val is 5999999 and time 5688
> >
> > Code For StringBuilder :
> >
> > using System;
> > using System.Collections.Generic;
> > using System.Text;
> >
> > namespace compareCompare
> > {
> > class Program
> > {
> > static void Main(string[] args)
> > {
> > int ini = Environment.TickCount;
> >
> > System.Text.StringBuilder k = new System.Text.StringBuilder();
> >
> > for (int i = 0; i < 6000000; ++i)
> > {
> > k = new System.Text.StringBuilder(i.ToString());
> > }
> >
> > Console.WriteLine("val is {0} and time {1}", k,
> > Environment.TickCount - ini);
> >
> > while (true)
> > {
> > if (Console.ReadKey() != null) break;
> > }
> >
> > }
> > }
> > }
> >
> >
> >
> >
> > 2007/11/22, pablosantosluac <pablosantosluac at terra.es>:
> >> Anyway, how would you use it in the sample I attached to improve
> >> performance? I need to convert a different integer each pass...
> >> ----- Original Message -----
> >> From: "Petit Eric" <surfzoid at gmail.com >
> >> To: "pablosantosluac" <pablosantosluac at terra.es>
> >> Cc: <mono-devel-list at lists.ximian.com >
> >> Sent: Thursday, November 22, 2007 10:24 AM
> >> Subject: Re: [Mono-dev] ToString() performace in Mono
> >>
> >>
> >> > Do you try to replace String by a System.Text.StringBuilder ?
> >> >
> >> > 2007/11/22, pablosantosluac <pablosantosluac at terra.es>:
> >> >> Hi,
> >> >>
> >> >>
> >> >> I've detected a performance hit on "plastic server" running on mono. I
> >> >> was
> >> >> actually shocked because when I checked something similar working with
> >> >> integers, Mono was actually faster than .NET. But it seems it is not
> >> >> the
> >> >> case with strings.
> >> >>
> >> >> Please consider the following code sample:
> >> >>
> >> >>
> >> >> using System;
> >> >>
> >> >> namespace compareCompare
> >> >> {
> >> >> class Class1
> >> >> {
> >> >> static void Main(string[] args)
> >> >> {
> >> >> int ini = Environment.TickCount;
> >> >>
> >> >> string k = string.Empty;
> >> >>
> >> >> for( int i = 0; i < 6000000; ++i )
> >> >> {
> >> >> k = i.ToString();
> >> >> }
> >> >>
> >> >> Console.WriteLine("val is {0} and time {1}", k,
> >> >> Environment.TickCount - ini);
> >> >> }
> >> >> }
> >> >> }
> >> >>
> >> >>
> >> >> 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
> >> >>
> >> >>
> >> >> Thanks,
> >> >>
> >> >>
> >> >> pablo
> >> >>
> >> >> _______________________________________________
> >> >> Mono-devel-list mailing list
> >> >> Mono-devel-list at lists.ximian.com
> >> >> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >> >>
> >>
> >>
>
>
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071122/d410b87f/attachment.html
More information about the Mono-devel-list
mailing list