Skip to content

Instantly share code, notes, and snippets.

@joaqo
Created March 10, 2020 21:41
Show Gist options
  • Save joaqo/e019b00ba0dae567bf7d66ee971f7c9e to your computer and use it in GitHub Desktop.
Save joaqo/e019b00ba0dae567bf7d66ee971f7c9e to your computer and use it in GitHub Desktop.
Just a silly short list sum script to provide as a baseline for benchmarking Swift code.
// clang -O3 -march=native deleteme.c -o del_c
#include <stdio.h>
#include <time.h>
int main () {
clock_t start, end;
double cpu_time_used;
int n[ 3000 ];
for (int tests = 0; tests < 15; tests++) {
start = clock();
int sum = 0;
for (int i = 0; i < 3000; i++) {
n[i] = tests;
}
for(int i=0; i<3000; i++) {
sum = sum + n[i];
}
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("%.6f", cpu_time_used);
printf(" %d", sum);
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment