fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main(){
  6. int j;
  7. const int n = 100000;
  8. double *a1p, *b1p, *c1p, *d1p;
  9.  
  10. #ifdef ALLOCATE_SEPERATE
  11. double *a1 = (double*)malloc(n * sizeof(double));
  12. double *b1 = (double*)malloc(n * sizeof(double));
  13. double *c1 = (double*)malloc(n * sizeof(double));
  14. double *d1 = (double*)malloc(n * sizeof(double));
  15. #else
  16. double *a1 = (double*)malloc(n * sizeof(double) * 4);
  17. double *b1 = a1 + n;
  18. double *c1 = b1 + n;
  19. double *d1 = c1 + n;
  20. #endif
  21.  
  22. // Zero the data to prevent any chance of denormals.
  23. memset(a1,0,n * sizeof(double));
  24. memset(b1,0,n * sizeof(double));
  25. memset(c1,0,n * sizeof(double));
  26. memset(d1,0,n * sizeof(double));
  27.  
  28. // Print the addresses
  29. cout << a1 << endl;
  30. cout << b1 << endl;
  31. cout << c1 << endl;
  32. cout << d1 << endl;
  33.  
  34. clock_t start = clock();
  35.  
  36. int c = 0;
  37. while (c++ < 10000){
  38.  
  39. #if ONE_LOOP
  40. for (a1p = a1, b1p = b1, c1p = c1, d1p = d1, j = n;
  41. j; a1p++, b1p++, c1p++, d1p++, j--)
  42. {
  43. *a1p += *b1p;
  44. *c1p += *d1p;
  45. }
  46. #else
  47. for (a1p = a1, b1p = b1, j = n;
  48. j; a1p++, b1p++, j--)
  49. {
  50. *a1p += *b1p;
  51. }
  52. for (c1p = c1, d1p = d1, j = n;
  53. j; c1p++, d1p++, j--)
  54. {
  55. *c1p += *d1p;
  56. }
  57. #endif
  58.  
  59. }
  60.  
  61. clock_t end = clock();
  62. cout << "seconds = " << (double)(end - start) / CLOCKS_PER_SEC << endl;
  63.  
  64. system("pause");
  65. return 0;
  66. }
Success #stdin #stdout #stderr 1.52s 6820KB
stdin
Standard input is empty
stdout
0x2ab9b1e69010
0x2ab9b1f2c510
0x2ab9b1fefa10
0x2ab9b20b2f10
seconds = 1.51273
stderr
sh: 1: pause: not found