gnokii-users
[Top][All Lists]
Advanced

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

Re: [PATCH] Using smsd to send multiline sms


From: Jan Derfinak
Subject: Re: [PATCH] Using smsd to send multiline sms
Date: Fri, 18 Jul 2008 19:22:43 +0200 (CEST)

On Fri, 18 Jul 2008, Pawel Kot wrote:

> > It returns NULL, but do not change destination string.
> 
> And I expect such behaviour in the code above.
> 
> > The idea of my construction is that memset initialize memory of the string
> > with 0.
> 
> My point is that it is too much (especially data.text is quite large).

So that only objection is that it is too expensive?
Text is defined as 10 * GN_SMS_MAX_LENGTH + 1 = 1601b. It is less
than page size. Do you thing that unconditionaly zeroing 1601b of continuous
data is much more expensive that branching and assigning?
OK, we can test it:

Memset example:
#include <stdio.h>
#include <string.h>

FILE *f;
char str[1601];

void ms (void)
{
  register long int i;
  
  for (i = 0; i < 10000000; i++)
  {
    memset (&str, 0, sizeof (str));
    fgets (str, 161, f);
  }
}

int main (void)
{
  f = fopen ("aaa.c", "r");
  
  ms ();
  
  fclose (f);
  
  return 0;
}


=======================================================================
Branching example:
#include <stdio.h>

FILE *f;
char str[1601];


void branch (void)
{
  register int i;
  
  for (i = 0; i < 10000000; i++)
  {
    if (!fgets (str, 161, f))
      str[0] = '\0';
  }

}


int main (void)
{
  f = fopen ("aaa.c", "r");
  
  branch ();
  
  fclose (f);
  
  return 0;
}

=========================================================================

Memset profiler output:
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
101.82      0.07     0.07        1    71.27    71.27  ms

...

granularity: each sample hit covers 2 byte(s) for 14.03% of 0.07 seconds

index % time    self  children    called     name
                0.07    0.00       1/1           main [2]
[1]    100.0    0.07    0.00       1         ms [1]
-----------------------------------------------
                                                 <spontaneous>
[2]    100.0    0.00    0.07                 main [2]
                0.07    0.00       1/1           ms [1]
-----------------------------------------------

==========================================================================

Branching profiler output:
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
101.86      0.14     0.14        1   142.61   142.61  branch

...

granularity: each sample hit covers 2 byte(s) for 7.01% of 0.14 seconds

index % time    self  children    called     name
                0.14    0.00       1/1           main [2]
[1]    100.0    0.14    0.00       1         branch [1]
-----------------------------------------------
                                                 <spontaneous>
[2]    100.0    0.00    0.14                 main [2]
                0.14    0.00       1/1           branch [1]
-----------------------------------------------

==========================================================================

So it looks that my construction is quicker.

jan


-- 




reply via email to

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