Reputation: 231
I iterate over a 3d array:
byte[, ,] data = original.Data;
for (int i = original.Rows - 1; i >= 0; i--)
{
for (int j = original.Cols - 1; j >= 0; j--)
{
if (data [i,j,0] < 100)
{
data [i, j, 0] += 100;
data [i, j, 1] += 40;
data [i, j, 2] += 243;
}
else
{
data [i,j,0] = 0;
}
}
}
I tested this code with a quite old x86 CPU (Intel Core Duo) and a quite new x64 CPU (Intel i7). I was very surprised to see, that the newer x64 CPU was much slower. The x64 needed three times more time! What is wrong with that code? What can I do to make the x64 code faster?
Additional Info: - Both tests were made on a win 7 os. (32-bit version for x86 and 64-bit version for x64) - Code is C#
Upvotes: 2
Views: 602
Reputation: 74692
You'd probably get much faster results if you were operating on 32-bit or 64-bit values (even if you were operating on perhaps 4 byte values at a time).
Upvotes: 1
Reputation: 564821
In general, many newer processors do tend to be slower than older processors, especially much older processors.
Newer processors, however, tend to have more cores and use much less power. This is part of why multithreading is becoming so much more important - you can't rely on future hardware to provide speed benefits.
In addition, 64bit code often runs slower than similar 32bit code. It does, however, provide other benefits, such as access to much larger amounts of memory.
Upvotes: 2