From ed6902cdcc8b02187cb6f7390a0f0dab14bc60c4 Mon Sep 17 00:00:00 2001 From: pjc97uv2f <1291955673@qq.com> Date: Sat, 23 Nov 2024 11:17:32 +0800 Subject: [PATCH] Add 1 --- 1 | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 1 diff --git a/1 b/1 new file mode 100644 index 0000000..190086b --- /dev/null +++ b/1 @@ -0,0 +1,42 @@ +#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; +} \ No newline at end of file