#include #include #include #define SIZE 1024 // the add function void vector_add(float* A, float* B, float* C, int size) { for (int i = 0; i < size; i++) { C[i] = A[i] + B[i]; } } int main() { // define the size float A[SIZE]; float B[SIZE]; float C[SIZE]; // use 'for' to random for (int i = 0; i < SIZE; i++) { A[i] = (float)(rand() % 100); B[i] = (float)(rand() % 100); } clock_t start_time, end_time; // get the start time start_time = clock(); // use the function vector_add(A, B, C, SIZE); // get the end time end_time = clock(); // get the time and transform to secound double elapsed_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; printf("基础向量加法的运行时间:%f 秒\n", elapsed_time); return 0; }