gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[6]: additional methods in NSMutableString


From: Manuel Guesdon
Subject: Re[6]: additional methods in NSMutableString
Date: Mon, 10 Jan 2005 19:23:03 +0100 (CET)

On Fri, 7 Jan 2005 11:12:51 +0100 Markus Hitter <address@hidden> wrote:

 >| 
 >| Am 06.01.2005 um 20:03 schrieb Manuel Guesdon:
 >| 
 >| > o about performances, ...
 >| 
 >| Well, you'll have to run some benchmarks to find out

I've done a simple one:

    int i=0;
    int max=10000;
    NSMutableString* ms=[NSMutableString new];
    [ms appendFormat:@"%@",@"a"];
    GSWTime tStart=GSWTime_now();
    for(i=0;i<max;i++)
        {
          [ms appendFormat:@"%@ ",@"a"];
        }
    GSWTime tStop=GSWTime_now();
    DESTROY(ms);
    NSLog(@"void: tStart=%@ tStop=%@ 
diff=%f",GSWTime_format(tStart),GSWTime_format(tStop),GSWTime_floatSec(tStop-tStart));
    
    ms=[NSMutableString new];
    [ms appendFormat:@"%@",@"a"];
    tStart=GSWTime_now();
    for(i=0;i<max;i++)
        {
          [ms appendFormat:@"%@ ",@"a"];
        }
    tStop=GSWTime_now();
    DESTROY(ms);
    NSLog(@"appendFormat: tStart=%@ tStop=%@ 
diff=%f",GSWTime_format(tStart),GSWTime_format(tStop),GSWTime_floatSec(tStop-tStart));

    ms=[NSMutableString new];
    [ms appendFormat:@"%@",@"a"];
    tStart=GSWTime_now();
    for(i=0;i<max;i++)
      {
        [ms appendString:@"a"];
        [ms appendString:@" "];
      }
    tStop=GSWTime_now();
    DESTROY(ms);
    NSLog(@"appendString: tStart=%@ tStop=%@ 
diff=%f",GSWTime_format(tStart),GSWTime_format(tStop),GSWTime_floatSec(tStop-tStart));

    ms=[NSMutableString new];
    [ms appendString:@"a"];
    tStart=GSWTime_now();
    SEL address@hidden(appendString:);
    IMP aImp=[ms methodForSelector:aSel];
    for(i=0;i<max;i++)
      {
        (*aImp)(ms,aSel,@"a");
        (*aImp)(ms,aSel,@" ");
      }
    tStop=GSWTime_now();
    DESTROY(ms);
    NSLog(@"appendString IMP: tStart=%@ tStop=%@ 
diff=%f",GSWTime_format(tStart),GSWTime_format(tStop),GSWTime_floatSec(tStop-tStart));

Here's  results:
1st case (just to try thats next tests are in the same condition): time spent: 
0.022303 s
2nd: use of appendWithFormat: 0.022340 s
3rd: 2 appendString: 0.011639s
4th: 2appendString with IMP: 0.011026 s

So using appendString: is better for this case (half time spent)
Using IMP is a little more faster than calling -appendString:

a second run:
1: 0.022326
2: 0.022372
3: 0.011659
4: 0.011041

with max=100000 and format  @"%@ %@" with @"a",@"b":
1: 0.375479
2: 0.380862
3: 0.172804
4: 0.163389



 >| Surely, you already know NAT!'s great article(s) about Objective C 
 >| optimization: <http://www.mulle-kybernetik.com/artikel/Optimization/>.

Yes. I've re-read it to try to find things to improve in gsweb and 
gdl2.



 >| - Compatibility with OpenStep / Cocoa degrades: You have to work around 
 >| these extensions if you want to have portable code. Portability is a 
 >| big plus of GNUstep.

It's in Additions/ so it can work on both plateform.


 >| - Adding a method fitting to a particular situation doesn't 
 >| automatically increase performance in this situation.

Methods proposed was not only for particuliar situation but more 
general.


Manuel 

--
______________________________________________________________________
Manuel Guesdon - OXYMIUM <address@hidden>
14 rue Jean-Baptiste Clement  -  93200 Saint-Denis  -  France
Tel: +33 1 4940 0999  -  Fax: +33 1 4940 0998





reply via email to

[Prev in Thread] Current Thread [Next in Thread]