title: Why does the asm code function in C, takes more time than the c code function?
body: <p>I wrote a simple multiplication function in C, and another in assembly code, using GCC's <code>"asm"</code> keyword.</p>
  
  <p>I took the execution time for each of them, and although their times are pretty close, the C function is a little faster than the one in assembly code. </p>
  
  <p>I would like to know why, since I expected for the asm one to be faster. Is it because of the extra "call" (i don't know what word to use) to the GCC's "asm" keyword? </p>
  
  <p>Here is the C function:</p>
  
  <pre><code>int multiply (int a, int b){return a*b;}
  </code></pre>
  
  <p>And here is the <code>asm</code> one in the C file:</p>
  
  <pre><code>int asmMultiply(int a, int b){  
      asm ("imull %1,%0;"
               : "+r" (a)           
               : "r" (b)
      );
      return a;
  }
  </code></pre>
  
  <p>my main where I take the times:</p>
  
  <pre><code>int main(){
     int n = 50000;
     clock_t asmClock = clock();
     while(n&gt;0){
         asmMultiply(4,5);
         n--;
      }
  
     asmClock = clock() - asmClock;  
     double asmTime = ((double)asmClock)/CLOCKS_PER_SEC; 
  
     clock_t cClock = clock();
     n = 50000;
     while(n&gt;0){
         multiply(4,5);
         n--;
     }
     cClock = clock() - cClock;  
     double cTime = ((double)cClock)/CLOCKS_PER_SEC;  
  
    printf("Asm time: %f\n",asmTime);
    printf("C code time: %f\n",cTime);
  </code></pre>
  
  <p>Thanks!</p>