parent
3778299bf8
commit
fc101d3b2d
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#define SIZE 1024
|
||||
|
||||
void vector_add_optimized(float* A, float* B, float* C, int size);
|
||||
int main() {
|
||||
float A[SIZE], B[SIZE], C[SIZE];
|
||||
int i;
|
||||
srand(time(0));
|
||||
for(i=0; i<SIZE; i++) {
|
||||
A[i] = rand() % 100;
|
||||
B[i] = rand() % 100;
|
||||
}
|
||||
|
||||
clock_t start = clock();
|
||||
vector_add_optimized(A, B, C, SIZE);
|
||||
clock_t end = clock();
|
||||
printf("初始向量加法时间:%lf\n", (double)(end-start) / CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
void vector_add_optimized(float* A, float* B, float* C, int size) {
|
||||
int i;
|
||||
for(i=0; i<size; i++) {
|
||||
C[i] = A[i] + B[i];
|
||||
}
|
||||
}
|
Loading…
Reference in new issue