Skip to content

Instantly share code, notes, and snippets.

@richlander
Created July 20, 2015 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richlander/73475dd0b14555c156c2 to your computer and use it in GitHub Desktop.
Save richlander/73475dd0b14555c156c2 to your computer and use it in GitHub Desktop.
Compute the sums of the values in two arrays of integers, with Vector<T>
// Task: Compute the sums of the values in two arrays of integers, A and B.
// Traditional approach:
for (int i = 0; i < size; i++)
{
C[i] = A[i] + B[i];
}
// With Vector<int> you can instead do this:
for (int i = 0; i < size; i += Vector<int>.Count)
{
Vector<int> v = new Vector<int>(A,i) + new Vector<int>(B,i);
v.CopyTo(C,i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment