Created
July 20, 2015 05:16
-
-
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>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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