StringBuilder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Skeet

    #16
    Re: StringBuilder

    Alvin Bruney <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote:[color=blue]
    > On the advice of a user, I've timed stringbuilder v string. Here are the
    > results.
    >
    > Here are the numbers:
    > Total # queries 3747
    > Time in Milliseconds
    >
    > StringBuilder: String
    > 460.6624 320.4608
    > 350.504 220.3168
    > 240.3456 230.3312
    > ----------- -----------
    > Ave. 350.504 Ave. 257.0362[/color]

    Just looking at these results again, I'm *sure* the bulk of the time is
    spent in executing the query. I certainly wouldn't expect it to take
    that long just building up the strings.

    Just for interest's sake, I ran a test where I built up 100000 strings,
    each of the form (hello)(hello)( hello).... (x50) in a similar way to
    most of your code. On my (admittedly faster) laptop, that took about
    half a second. Here's the code:

    using System;
    using System.Text;

    public class Test
    {
    public static void Main(string[] args)
    {
    DateTime start = DateTime.Now;

    for (int i=0; i < 100000; i++)
    {
    StringBuilder sb = new StringBuilder() ;
    for (int j=0; j < 50; j++)
    {
    sb.Append ('(').Append("h ello").Append(' )');
    }
    }

    DateTime end = DateTime.Now;
    Console.WriteLi ne (end-start);
    }
    }

    Given those results, I really suspect that very little of your time is
    spent actually building the strings.

    One thing you *could* do to improve your code is change lines such as:

    strTempString.A ppend("'").Appe nd(splitField[RATE]).Append("',");
    strTempString.A ppend("'").Appe nd(splitField[SURCHARGE]).Append("',");
    strTempString.A ppend("'").Appe nd(splitField[MIN_SEC]).Append("',");
    strTempString.A ppend("'").Appe nd(splitField[INCR_SEC]).Append("',");

    to:

    strTempString.A ppend("'");
    strTempString.A ppend(splitFiel d[RATE]).Append("','") ;
    strTempString.A ppend(splitFiel d[SURCHARGE]).Append("','") ;
    strTempString.A ppend(splitFiel d[MIN_SEC]).Append("','") ;
    strTempString.A ppend(splitFiel d[INCR_SEC]).Append("'.");

    etc which would reduce the number of appends by a third. I suspect you
    won't see much difference though, for the reasons given above.

    Out of interest, is there any reason for not using parameterised
    queries and then passing in the parameters? I would expect that could
    be faster at both the query-building end (with fewer variables
    involved) and at the database end.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Alvin Bruney

      #17
      Re: StringBuilder

      ok (long okayyyyyyyyyyyy y).

      I am attaching the complete routine with a short explanation.
      This routine constructs queries and returns them on an arraylist. That is
      all that was timed. Another threaded routine somewhere else takes care of
      the database write. That routine has no knowledge of the construction
      process and was not timed. For the test, the listbox had 3 items. (1249
      queries repeated 3 times = 3747).
      With this supplied code it would be trivial to reproduce the results. I
      already said how I changed the appends to strings.

      The times are in milliseconds by the way not seconds, which is a good time
      IMO all things considered.

      I purposely stay away from contrived examples because usually these examples
      in no way mimic the demands of real world applications. Therefore, and for
      the most part, the results can only be used as a rough guideline, certainly
      not an absolute.

      I didn't say that microsoft is lying. Do not misquote me. I alluded to the
      fact that they may have overstated the facts (hype), reported results on the
      extremely optimistic side (long history of doing so) etc etc. Can you find a
      quote of me calling them liars?

      On the other hand, I remain suspicious of MS' conclusions because lately
      questions have arisen which seem to not support MS' claims. Case in point,
      the garbage collector DOES NOT actually return recycled memory to the
      operating system. MS now claims this is a bug somewhere deep in their
      framework, but it bellies the point that their claim of garbage collection
      was not correct in the first place.

      I will continue to be vigilant. I still think .net is the greatest thing
      since sliced bread. I am just more cautious about repeating stuff from the
      microsoft marketing machine. If you think my results are completely bogus,
      you are welcomed to post your times.














      yada yada yada they lied
      "Jon Skeet" <skeet@pobox.co m> wrote in message
      news:MPG.19db55 ba4ca5dfec98973 8@news.microsof t.com...[color=blue]
      > Alvin Bruney <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote:[color=green]
      > > On the advice of a user, I've timed stringbuilder v string. Here are the
      > > results.
      > >
      > > Here are the numbers:
      > > Total # queries 3747
      > > Time in Milliseconds
      > >
      > > StringBuilder: String
      > > 460.6624 320.4608
      > > 350.504 220.3168
      > > 240.3456 230.3312
      > > ----------- -----------
      > > Ave. 350.504 Ave. 257.0362[/color]
      >
      > Just looking at these results again, I'm *sure* the bulk of the time is
      > spent in executing the query. I certainly wouldn't expect it to take
      > that long just building up the strings.
      >
      > Just for interest's sake, I ran a test where I built up 100000 strings,
      > each of the form (hello)(hello)( hello).... (x50) in a similar way to
      > most of your code. On my (admittedly faster) laptop, that took about
      > half a second. Here's the code:
      >
      > using System;
      > using System.Text;
      >
      > public class Test
      > {
      > public static void Main(string[] args)
      > {
      > DateTime start = DateTime.Now;
      >
      > for (int i=0; i < 100000; i++)
      > {
      > StringBuilder sb = new StringBuilder() ;
      > for (int j=0; j < 50; j++)
      > {
      > sb.Append ('(').Append("h ello").Append(' )');
      > }
      > }
      >
      > DateTime end = DateTime.Now;
      > Console.WriteLi ne (end-start);
      > }
      > }
      >
      > Given those results, I really suspect that very little of your time is
      > spent actually building the strings.
      >
      > One thing you *could* do to improve your code is change lines such as:
      >
      > strTempString.A ppend("'").Appe nd(splitField[RATE]).Append("',");
      > strTempString.A ppend("'").Appe nd(splitField[SURCHARGE]).Append("',");
      > strTempString.A ppend("'").Appe nd(splitField[MIN_SEC]).Append("',");
      > strTempString.A ppend("'").Appe nd(splitField[INCR_SEC]).Append("',");
      >
      > to:
      >
      > strTempString.A ppend("'");
      > strTempString.A ppend(splitFiel d[RATE]).Append("','") ;
      > strTempString.A ppend(splitFiel d[SURCHARGE]).Append("','") ;
      > strTempString.A ppend(splitFiel d[MIN_SEC]).Append("','") ;
      > strTempString.A ppend(splitFiel d[INCR_SEC]).Append("'.");
      >
      > etc which would reduce the number of appends by a third. I suspect you
      > won't see much difference though, for the reasons given above.
      >
      > Out of interest, is there any reason for not using parameterised
      > queries and then passing in the parameters? I would expect that could
      > be faster at both the query-building end (with fewer variables
      > involved) and at the database end.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]




      Comment

      • Alvin Bruney

        #18
        Re: StringBuilder

        ok (long okayyyyyyyyyyyy y).

        I am attaching the complete routine with a short explanation.
        This routine constructs queries and returns them on an arraylist. That is
        all that was timed. Another threaded routine somewhere else takes care of
        the database write. That routine has no knowledge of the construction
        process and was not timed. For the test, the listbox had 3 items. (1249
        queries repeated 3 times = 3747).
        With this supplied code it would be trivial to reproduce the results. I
        already said how I changed the appends to strings.

        The times are in milliseconds by the way not seconds, which is a good time
        IMO all things considered.

        I purposely stay away from contrived examples because usually these examples
        in no way mimic the demands of real world applications. Therefore, and for
        the most part, the results can only be used as a rough guideline, certainly
        not an absolute.

        I didn't say that microsoft is lying. Do not misquote me. I alluded to the
        fact that they may have overstated the facts (hype), reported results on the
        extremely optimistic side (long history of doing so) etc etc. Can you find a
        quote of me calling them liars?

        On the other hand, I remain suspicious of MS' conclusions because lately
        questions have arisen which seem to not support MS' claims. Case in point,
        the garbage collector DOES NOT actually return recycled memory to the
        operating system. MS now claims this is a bug somewhere deep in their
        framework, but it bellies the point that their claim of garbage collection
        was not correct in the first place.

        I will continue to be vigilant. I still think .net is the greatest thing
        since sliced bread. I am just more cautious about repeating stuff from the
        microsoft marketing machine. If you think my results are completely bogus,
        you are welcomed to post your times.














        yada yada yada they lied
        "Jon Skeet" <skeet@pobox.co m> wrote in message
        news:MPG.19db55 ba4ca5dfec98973 8@news.microsof t.com...[color=blue]
        > Alvin Bruney <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote:[color=green]
        > > On the advice of a user, I've timed stringbuilder v string. Here are the
        > > results.
        > >
        > > Here are the numbers:
        > > Total # queries 3747
        > > Time in Milliseconds
        > >
        > > StringBuilder: String
        > > 460.6624 320.4608
        > > 350.504 220.3168
        > > 240.3456 230.3312
        > > ----------- -----------
        > > Ave. 350.504 Ave. 257.0362[/color]
        >
        > Just looking at these results again, I'm *sure* the bulk of the time is
        > spent in executing the query. I certainly wouldn't expect it to take
        > that long just building up the strings.
        >
        > Just for interest's sake, I ran a test where I built up 100000 strings,
        > each of the form (hello)(hello)( hello).... (x50) in a similar way to
        > most of your code. On my (admittedly faster) laptop, that took about
        > half a second. Here's the code:
        >
        > using System;
        > using System.Text;
        >
        > public class Test
        > {
        > public static void Main(string[] args)
        > {
        > DateTime start = DateTime.Now;
        >
        > for (int i=0; i < 100000; i++)
        > {
        > StringBuilder sb = new StringBuilder() ;
        > for (int j=0; j < 50; j++)
        > {
        > sb.Append ('(').Append("h ello").Append(' )');
        > }
        > }
        >
        > DateTime end = DateTime.Now;
        > Console.WriteLi ne (end-start);
        > }
        > }
        >
        > Given those results, I really suspect that very little of your time is
        > spent actually building the strings.
        >
        > One thing you *could* do to improve your code is change lines such as:
        >
        > strTempString.A ppend("'").Appe nd(splitField[RATE]).Append("',");
        > strTempString.A ppend("'").Appe nd(splitField[SURCHARGE]).Append("',");
        > strTempString.A ppend("'").Appe nd(splitField[MIN_SEC]).Append("',");
        > strTempString.A ppend("'").Appe nd(splitField[INCR_SEC]).Append("',");
        >
        > to:
        >
        > strTempString.A ppend("'");
        > strTempString.A ppend(splitFiel d[RATE]).Append("','") ;
        > strTempString.A ppend(splitFiel d[SURCHARGE]).Append("','") ;
        > strTempString.A ppend(splitFiel d[MIN_SEC]).Append("','") ;
        > strTempString.A ppend(splitFiel d[INCR_SEC]).Append("'.");
        >
        > etc which would reduce the number of appends by a third. I suspect you
        > won't see much difference though, for the reasons given above.
        >
        > Out of interest, is there any reason for not using parameterised
        > queries and then passing in the parameters? I would expect that could
        > be faster at both the query-building end (with fewer variables
        > involved) and at the database end.
        >
        > --
        > Jon Skeet - <skeet@pobox.co m>
        > http://www.pobox.com/~skeet
        > If replying to the group, please do not mail me too[/color]




        Comment

        • Jon Skeet

          #19
          Re: StringBuilder

          [Apologies for the code at the end not wrapping nicely. Reformatting all
          of those lines to get them to under 72 columns would have taken forever.]

          Alvin Bruney <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote:[color=blue]
          > ok (long okayyyyyyyyyyyy y).
          >
          > I am attaching the complete routine with a short explanation.
          > This routine constructs queries and returns them on an arraylist. That is
          > all that was timed. Another threaded routine somewhere else takes care of
          > the database write.[/color]

          Hang on - you've got other threads running at the same time? If so, that
          *completely* stuffs up the tests. You should run the tests on an otherwise
          idle machine.
          [color=blue]
          > That routine has no knowledge of the construction
          > process and was not timed. For the test, the listbox had 3 items. (1249
          > queries repeated 3 times = 3747).
          > With this supplied code it would be trivial to reproduce the results. I
          > already said how I changed the appends to strings.[/color]

          Except no, it's *not* trivial to reproduce the results, because it refers
          to all kinds of variables for which we haven't the faintest idea of real
          world values. However, I've done it, in a fashion - see later.
          [color=blue]
          > The times are in milliseconds by the way not seconds, which is a good time
          > IMO all things considered.[/color]

          Except it's not, given the times I posted earlier, where 100,000 sets of appends
          (with 50 iterations in each set, appending 3 times per iteration - in other
          words, more work than it looks like is happening in your routine) took only
          half a second.
          [color=blue]
          > I purposely stay away from contrived examples because usually these examples
          > in no way mimic the demands of real world applications. Therefore, and for
          > the most part, the results can only be used as a rough guideline, certainly
          > not an absolute.[/color]

          So give real world examples of the variables used in your test, and we can
          try to reproduce things, and improve the times.
          [color=blue]
          > I didn't say that microsoft is lying.[/color]

          You said:

          <quote>
          My conclusion is: I think these microsoft guys have been feeding us a bunch
          of bullshit with this stringbuilder efficiency crap.
          </quote>
          [color=blue]
          > Do not misquote me.[/color]

          The above is an exact quote. If someone is "feeding us a bunch of bullshit"
          that says to me that they're lying.
          [color=blue]
          > I alluded to the fact that they may have overstated the facts (hype)[/color]

          Overstating is lying.
          [color=blue]
          > reported results on the extremely optimistic side (long history of doing so)
          > etc etc. Can you find a quote of me calling them liars?[/color]

          I don't think there are many people who wouldn't view "feeding us a bunch of
          bullshit" as lying.
          [color=blue]
          > On the other hand, I remain suspicious of MS' conclusions because lately
          > questions have arisen which seem to not support MS' claims. Case in point,
          > the garbage collector DOES NOT actually return recycled memory to the
          > operating system. MS now claims this is a bug somewhere deep in their
          > framework, but it bellies the point that their claim of garbage collection
          > was not correct in the first place.[/color]

          I don't think there's anything sinister going on - they just have a bug,
          which is understandable. That's not the same situation at all as with
          StringBuilder, which has been shown time and time again to be faster in
          situations like yours.
          [color=blue]
          > I will continue to be vigilant. I still think .net is the greatest thing
          > since sliced bread. I am just more cautious about repeating stuff from the
          > microsoft marketing machine. If you think my results are completely bogus,
          > you are welcomed to post your times.[/color]

          Kinda difficult without any sample values, isn't it? However, I've done my best -
          see below.
          [color=blue]
          > yada yada yada they lied[/color]

          Pardon?


          Anyway, I've taken your code and bodged it around so that it'll compile, giving it
          some dummy values etc.

          It creates a total of 300,000 queries in 100,000 iterations (3 per iteration, just
          like yours). My results are:

          10000 iterations took 00:00:01.640625 0
          10000 iterations took 00:00:01.625000 0
          10000 iterations took 00:00:01.625000 0

          In other words, it's doing nearly 100 times as much work as your tests, in less than 10
          times the time. I don't believe my computer is 10 times faster than yours - I believe
          that your tests were just broken, basically. Why don't you run the code below for
          yourself, and see what happens. If you get much faster times than you did before, the
          natural conclusion (IMO) is that most of the time spent in your previous tests wasn't
          spent running the query-building code - and thus your tests are invalidated.



          Here's the code:


          using System;
          using System.Text;
          using System.Collecti ons;

          class Test
          {
          // Dummy variables
          string[] items = {"COPYRATE1" , "COPYRATE2" , "COPYRATE3" };
          bool ForceCreateChec ked = true;

          int NEW_RATE=0;
          int NEW_RATE_DATE=1 ;
          // 2 is used directly elsewhere
          int RATE=7;
          int SURCHARGE=3;
          int MIN_SEC=4;
          int INCR_SEC=5;
          int BEGIN_DATE=6;

          static void Main()
          {
          // Repeat multiple times to allow for JITting.
          for (int j=0; j < 3; j++)
          {
          DateTime start = DateTime.Now;
          for (int i=0; i < 100000; i++)
          {
          new Test().SuckTheJ uiceOut("newrat e,newdate,1STAM ERICAN,0,0,0,21 50-01-01 12:00:00"+
          ",0,a,b,c,d,e,f ,g,h,i,j,k,l,m, n,o,p,q,r,s,t,u ,v,w,x,y,z,0,1, 2");
          }
          DateTime end = DateTime.Now;
          Console.WriteLi ne ("100000 iterations took {0}", end-start);
          }
          }

          private ArrayList SuckTheJuiceOut (string databaseBound)
          {
          /*
          if(RateDeckConf irm.Items.Count == 0)
          {
          Page.Controls.A dd(new LiteralControl( "<script>alert( 'An error has occurred. "+
          "The target rate deck is empty. Please refill this to continue.')</script>"));
          return null;
          }
          */

          // Not sure what this line was doing, nor why splitField2 isn't a local variable
          // splitField2 = GlobalRateMan.R egexNewline.Spl it(databaseBoun d);

          string[] splitField2 = databaseBound.S plit ('\n');

          ArrayList sql= new ArrayList();

          //we build the query here, take the records out the back end, it's more efficient that way
          //stuff a dummyfield to help us remove the first hidden record
          StringBuilder strTempString = new StringBuilder() ;

          // Changed GlobalRateMan.I NIT_VALUE to 0 here and elsewhere; if it's not 0, I don't know what it is.
          for(int index = 0; index < splitField2.Len gth; index++)
          {
          // Split by commas using just string.Split for the moment
          // splitField = GlobalRateMan.R egexComma.Split (splitField2[index]);

          // Again, why isn't splitField a local variable?
          string[] splitField = splitField2[index].Split(',');
          // Removed the "." here so I can just have a single variable
          if(ForceCreateC hecked)
          // I don't know what GlobalRateMan.s qlUpdateActiveR ate1/2 are, so I've just got literals here
          strTempString.A ppend("Update ds_active_rate SET (rate, surcharge, "+
          "min_sec, increment_sec, "+
          "begin_date , new_rate, new_rate_date, location_desc, "+
          "category_i d, country_code, customer_number , user_name)=(");
          else
          strTempString.A ppend("Update ds_active_rate1 SET (rate, surcharge, "+
          "min_sec, increment_sec, "+
          "begin_date , new_rate, new_rate_date, location_desc, "+
          "category_i d, country_code, customer_number , user_name)=(");
          //check for valid record. replace some excel formatting
          if(splitField.L ength == 37)
          {
          // Changed the location of the declarations of these variables, and put
          // the assignment of data alongside the declarations. I don't know what
          // FormatDate does, so I'm just going to assume we've passed in the
          // right format for the moment.
          string newrate = splitField[NEW_RATE];
          string newdate = splitField[NEW_RATE_DATE];

          //both fields must be entered or neither in the case of updates to field like surcharges
          if(newrate.Leng th > 0 && newdate.Length > 0)
          {
          //rate, surcharge, min_sec, increment_sec, begin_date, new_rate, new_rate_date, user_name
          //temporarily insert rate_id so we can set the where clause. remove it later
          strTempString.A ppend("'").Appe nd(splitField[RATE]).Append("',");
          strTempString.A ppend("'").Appe nd(splitField[SURCHARGE]).Append("',");
          strTempString.A ppend("'").Appe nd(splitField[MIN_SEC]).Append("',");
          strTempString.A ppend("'").Appe nd(splitField[INCR_SEC]).Append("',");
          // Again, ignore FormatDate
          strTempString.A ppend("'").Appe nd(splitField[BEGIN_DATE]).Append("',");
          // Assume GlobalRateMan.E MPTY==""
          strTempString.A ppend("'").Appe nd(newrate.Repl ace("$","")).Ap pend("',");
          strTempString.A ppend("'").Appe nd(newdate).App end("',");
          strTempString.A ppend("'").Appe nd(InsertUserNa me().TrimEnd()) .Append("')");

          // Removed the "." here so I can just have a single variable
          if(ForceCreateC hecked)
          {
          strTempString.A ppend("'").Appe nd(splitField[8] + "',");
          strTempString.A ppend(splitFiel d[12]).Append(",");
          strTempString.A ppend(splitFiel d[14]).Append(",");
          strTempString.A ppend("'").Appe nd(splitField[2]).Append("',");
          }
          }

          strTempString = strTempString.R eplace("',)","' )");
          if(newrate.Leng th == 0 && newdate.Length == 0)
          strTempString = strTempString.R eplace("new_rat e,new_rate_date ,","");

          for(int i = 0; i < items.Length; i++)
          {
          // Create a new StringBuilder each time - cleaner code
          StringBuilder strTempString2 = new StringBuilder() ;
          strTempString2. Append(" where rate_deck = '").Append(item s[i].TrimEnd()).App end("'");
          strTempString2. Append(" and location_id = ").Append(split Field[16]);
          strTempString2. Append(" and world_id = ").Append(split Field[10]);
          strTempString2. Append(" and rate_level = ").Append(split Field[34]);

          //caught a live one
          sql.Add(strTemp String + strTempString2. ToString());

          }

          // I don't think any of this is needed
          // strTempString.L ength = GlobalRateMan.I NITVALUE;
          // newrate = newdate = "";
          }
          }

          return sql;
          }

          string InsertUserName( )
          {
          return "jon";
          }
          }

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Jon Skeet

            #20
            Re: StringBuilder

            Jon Skeet <skeet@pobox.co m> wrote:

            <snip>

            Just for kicks, I had a go at using string concatenation instead. It
            took longer, but not *that* much longer. I looked a bit closer, and
            found that a significant amount of the time was being taken up by
            String.Split in my implementation - if you're using a Regex to split
            the data, that could account for quite a lot of your time difference.
            (I discovered this by only splitting the string once at the start of
            the program, and using the split form. Obviously you can't do this in
            your code, but it does point to the bottleneck not being in the
            appending.)

            Further, I found that the replacement:
            strTempString = strTempString.R eplace("',)","' )");
            took a fair amount of the time.

            Getting rid of the appending entirely by giving a list of 38 fields
            instead of 37 only cut the time down by a factor of 2 or so - which
            means that the difference in time spent actually appending is much more
            significant than it first appeared - I reckon that the actual guts of
            the appends are about 50% slower using string concatenation than using
            StringBuilder. The time can further be reduced by giving the
            StringBuilder constructors realistic capacities to start with - I gave
            400 and 200, and it made a significant difference.

            You might also be able to make things faster (and more readable) using
            String.Format, or StringBuilder.A ppendFormat. It would at least be
            worth a try - but I really don't think the appends are what's taking
            the time here.

            As well as the split, the final append for each item is also going to
            take a significant length of time whatever you do, by the way.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • Alvin Bruney

              #21
              Re: StringBuilder

              I'll get back to this in a couple hours. You have raised some valid concerns
              and I need to spend some time examining these concerns with the 'bullshit
              detector' light turned on. (that was light humor by the way. it really was).
              I think i'll also attach the contents of the splitstring as well as the
              other variables. I'm willing to consider the fact that breaking into the
              debugger could have thrown the times off.

              "Jon Skeet" <skeet@pobox.co m> wrote in message
              news:MPG.19dcbb 0bd869e88298975 2@news.microsof t.com...[color=blue]
              > Jon Skeet <skeet@pobox.co m> wrote:
              >
              > <snip>
              >
              > Just for kicks, I had a go at using string concatenation instead. It
              > took longer, but not *that* much longer. I looked a bit closer, and
              > found that a significant amount of the time was being taken up by
              > String.Split in my implementation - if you're using a Regex to split
              > the data, that could account for quite a lot of your time difference.
              > (I discovered this by only splitting the string once at the start of
              > the program, and using the split form. Obviously you can't do this in
              > your code, but it does point to the bottleneck not being in the
              > appending.)
              >
              > Further, I found that the replacement:
              > strTempString = strTempString.R eplace("',)","' )");
              > took a fair amount of the time.
              >
              > Getting rid of the appending entirely by giving a list of 38 fields
              > instead of 37 only cut the time down by a factor of 2 or so - which
              > means that the difference in time spent actually appending is much more
              > significant than it first appeared - I reckon that the actual guts of
              > the appends are about 50% slower using string concatenation than using
              > StringBuilder. The time can further be reduced by giving the
              > StringBuilder constructors realistic capacities to start with - I gave
              > 400 and 200, and it made a significant difference.
              >
              > You might also be able to make things faster (and more readable) using
              > String.Format, or StringBuilder.A ppendFormat. It would at least be
              > worth a try - but I really don't think the appends are what's taking
              > the time here.
              >
              > As well as the split, the final append for each item is also going to
              > take a significant length of time whatever you do, by the way.
              >
              > --
              > Jon Skeet - <skeet@pobox.co m>
              > http://www.pobox.com/~skeet
              > If replying to the group, please do not mail me too[/color]


              Comment

              Working...