c - Array compare with memcmp vs element by element comparsion -


this question has answer here:

which implementation better , why?

element element comparison using loop or memcmp() implementation

int a[] = {1,2,3}; int b[] = {1,3,5};  memcmp(a, b, sizeof(int)*n) 

or

 (i = 0; < n ; i++)     {        if (a[i] == b[i])         {             /* code */         }     } 

memcmp faster: heavily optimized compiler use special instructions on cpu, loop unrolling, , other "advanced" techniques generated code simple loop (generally) won't use. however, memcmp can compare byte values; fine in case of array of integers, (probably) wouldn't work array of objects.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -