title: Speed of memset Vs direct assignment to zero
body: <p>Please consider a struct definition below.</p>
  
  <pre><code>struct xyz {
    char a;
    void *ptr;
    uint16_t num1;
    uint32_t num2;
    uint64_t num3;
  };
  </code></pre>
  
  <p>I can initialize an instance of this structure to zero in one of 3 ways as below.</p>
  
  <ol>
  <li><p>At time of declaration</p>
  
  <pre><code>struct xyz instance = { 0 };
  </code></pre></li>
  <li><p>Sometime after declaring it using the C-99 feature.</p>
  
  <pre><code>instance = (const struct xyz) { 0 };
  </code></pre></li>
  </ol>
  
  <p>3.<code>memset (&amp;instance, 0, sizeof (struct xyz));</code></p>
  
  <p>A typical C struct could have some padding added by the compiler for alignment purpose.
  So memset will initialize the padding bytes also to zero.</p>
  
  <p>My question is:</p>
  
  <p>In general, will initialization by method 1 or 2 above be faster than method 3?
  It doesn't matter how many CPU cycles are saved, I am just curious if 1 &amp; 2 are faster than 3 or not.</p>