Z
zaeminkr
Hello.
I believed below two functions would have same performance.
However, I realized the second form of array iteration are found more
in many performance critical code like Microsoft CRT source code.
Really the second form of array iteration(count_neg2) is faster?
Thanks in advance.
**************************************************************************
unsigned int count_neg1(int* int_array, unsigned int n)
{
unsigned int c = 0;
unsigned int i = 0;
while(i < n)
{
if(int_array[i++] < 0)
{
++c;
}
}
return c;
}
**************************************************************************
unsigned int count_neg2(int* int_array, unsigned int n)
{
unsigned int c = 0;
int* end = int_array + n;
while(int_array < end)
{
if(*int_array++ < 0)
{
++c;
}
}
return c;
}
I believed below two functions would have same performance.
However, I realized the second form of array iteration are found more
in many performance critical code like Microsoft CRT source code.
Really the second form of array iteration(count_neg2) is faster?
Thanks in advance.
**************************************************************************
unsigned int count_neg1(int* int_array, unsigned int n)
{
unsigned int c = 0;
unsigned int i = 0;
while(i < n)
{
if(int_array[i++] < 0)
{
++c;
}
}
return c;
}
**************************************************************************
unsigned int count_neg2(int* int_array, unsigned int n)
{
unsigned int c = 0;
int* end = int_array + n;
while(int_array < end)
{
if(*int_array++ < 0)
{
++c;
}
}
return c;
}