Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int top = 999999999;
- char *a;
- a = (char*) calloc(top+1, sizeof(char));
- unsigned int sum = 0;
- for (int i=0; i<10; ++i) {
- int m, k;
- // (tested with cc -O3 t.c && /usr/bin/time -lp ./a.out)
- // (cc is Apple LLVM version 7.0.0)
- // This code ran in ~0.90 seconds on my system
- // char *b = a + top;
- // a++;
- // for (; a < b; )
- // {
- // sum += ( *a++ ) * ( *b--);
- // }
- // This code ran in ~5 seconds on my system
- for (m = 1, k = top; m < k; ++m, --k) {
- // Here is the bottle neck!!
- sum += a[m]*a[k];
- }
- }
- printf("%d\n", sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement