SHARE
TWEET

Untitled

a guest Dec 13th, 2015 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.     int top = 999999999;
  6.  
  7.     char *a;
  8.     a = (char*) calloc(top+1, sizeof(char));
  9.     unsigned int sum = 0;
  10.  
  11.     for (int i=0; i<10; ++i) {
  12.         int m, k;
  13.         // (tested with cc -O3 t.c && /usr/bin/time -lp ./a.out)
  14.         // (cc is Apple LLVM version 7.0.0)
  15.  
  16.         // This code ran in ~0.90 seconds on my system
  17. //        char *b = a + top;
  18. //        a++;
  19. //        for (; a < b; )
  20. //        {
  21. //            sum += ( *a++ ) * ( *b--);
  22. //        }
  23.  
  24.         // This code ran in ~5 seconds on my system
  25.         for (m = 1, k = top; m < k; ++m, --k) {
  26.             // Here is the bottle neck!!
  27.             sum += a[m]*a[k];
  28.         }
  29.     }
  30.     printf("%d\n", sum);
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top