fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. double sec(){
  7. struct timespec t;
  8. clock_gettime(CLOCK_MONOTONIC, &t);
  9. return t.tv_sec + 1e-9*t.tv_nsec;
  10. }
  11.  
  12. int main(){
  13. size_t n_bytes = 16*1000*1000*sizeof(double);
  14. int *src_initialized = (int*)malloc(n_bytes);
  15. int *src_uninitialized = (int*)malloc(n_bytes);
  16. int *dst_initialized = (int*)malloc(n_bytes);
  17. int *dst_uninitialized = (int*)malloc(n_bytes);
  18.  
  19. memset(src_initialized, 0, n_bytes);
  20.  
  21. for (int k = 0; k < 100; k++){
  22. double t0 = sec();
  23.  
  24. memcpy(dst_initialized, src_initialized, n_bytes);
  25.  
  26. double t1 = sec();
  27.  
  28. memcpy(dst_uninitialized, src_uninitialized, n_bytes);
  29.  
  30. double t2 = sec();
  31.  
  32. double initialized_gbps = n_bytes*1e-9/(t1 - t0);
  33. double uninitialized_gbps = n_bytes*1e-9/(t2 - t1);
  34.  
  35. printf(" initialized: %f gbyte/sec\n", initialized_gbps);
  36. printf("uninitialized: %f gbyte/sec\n", uninitialized_gbps);
  37. printf("\n");
  38. }
  39.  
  40. free(src_initialized);
  41. free(src_uninitialized);
  42. free(dst_initialized);
  43. free(dst_uninitialized);
  44.  
  45. return 0;
  46. }
  47.  
  48.  
Success #stdin #stdout 1.47s 15232KB
stdin
Standard input is empty
stdout
  initialized: 2.787793 gbyte/sec
uninitialized: 2.850523 gbyte/sec

  initialized: 18.948922 gbyte/sec
uninitialized: 19.112294 gbyte/sec

  initialized: 18.950698 gbyte/sec
uninitialized: 19.166945 gbyte/sec

  initialized: 19.140081 gbyte/sec
uninitialized: 18.489877 gbyte/sec

  initialized: 18.060955 gbyte/sec
uninitialized: 18.146573 gbyte/sec

  initialized: 17.535614 gbyte/sec
uninitialized: 17.412606 gbyte/sec

  initialized: 16.493588 gbyte/sec
uninitialized: 16.632929 gbyte/sec

  initialized: 18.436422 gbyte/sec
uninitialized: 18.315426 gbyte/sec

  initialized: 18.804894 gbyte/sec
uninitialized: 19.032260 gbyte/sec

  initialized: 18.947981 gbyte/sec
uninitialized: 19.158545 gbyte/sec

  initialized: 19.049671 gbyte/sec
uninitialized: 19.169468 gbyte/sec

  initialized: 19.043209 gbyte/sec
uninitialized: 18.444359 gbyte/sec

  initialized: 18.491151 gbyte/sec
uninitialized: 18.756094 gbyte/sec

  initialized: 18.923228 gbyte/sec
uninitialized: 19.037153 gbyte/sec

  initialized: 18.620682 gbyte/sec
uninitialized: 18.512710 gbyte/sec

  initialized: 18.207848 gbyte/sec
uninitialized: 17.206436 gbyte/sec

  initialized: 14.764995 gbyte/sec
uninitialized: 18.378614 gbyte/sec

  initialized: 18.143660 gbyte/sec
uninitialized: 19.047558 gbyte/sec

  initialized: 18.974664 gbyte/sec
uninitialized: 19.156985 gbyte/sec

  initialized: 19.132578 gbyte/sec
uninitialized: 19.080242 gbyte/sec

  initialized: 19.090695 gbyte/sec
uninitialized: 19.062184 gbyte/sec

  initialized: 19.132877 gbyte/sec
uninitialized: 19.130597 gbyte/sec

  initialized: 19.111933 gbyte/sec
uninitialized: 19.107001 gbyte/sec

  initialized: 19.079077 gbyte/sec
uninitialized: 18.135406 gbyte/sec

  initialized: 15.386207 gbyte/sec
uninitialized: 14.701555 gbyte/sec

  initialized: 14.410671 gbyte/sec
uninitialized: 18.372050 gbyte/sec

  initialized: 18.158542 gbyte/sec
uninitialized: 17.725825 gbyte/sec

  initialized: 18.851218 gbyte/sec
uninitialized: 19.095448 gbyte/sec

  initialized: 19.131343 gbyte/sec
uninitialized: 19.087513 gbyte/sec

  initialized: 19.137630 gbyte/sec
uninitialized: 19.110508 gbyte/sec

  initialized: 19.088235 gbyte/sec
uninitialized: 19.160425 gbyte/sec

  initialized: 19.146118 gbyte/sec
uninitialized: 19.112273 gbyte/sec

  initialized: 19.077721 gbyte/sec
uninitialized: 18.560150 gbyte/sec

  initialized: 18.509599 gbyte/sec
uninitialized: 17.756769 gbyte/sec

  initialized: 16.685803 gbyte/sec
uninitialized: 16.862285 gbyte/sec

  initialized: 17.320931 gbyte/sec
uninitialized: 17.538801 gbyte/sec

  initialized: 18.906090 gbyte/sec
uninitialized: 19.037533 gbyte/sec

  initialized: 19.141510 gbyte/sec
uninitialized: 19.076768 gbyte/sec

  initialized: 19.140593 gbyte/sec
uninitialized: 19.172100 gbyte/sec

  initialized: 19.085520 gbyte/sec
uninitialized: 19.040086 gbyte/sec

  initialized: 19.036879 gbyte/sec
uninitialized: 19.167223 gbyte/sec

  initialized: 19.092095 gbyte/sec
uninitialized: 19.111571 gbyte/sec

  initialized: 18.420390 gbyte/sec
uninitialized: 18.551072 gbyte/sec

  initialized: 17.744261 gbyte/sec
uninitialized: 16.979427 gbyte/sec

  initialized: 17.754530 gbyte/sec
uninitialized: 18.661965 gbyte/sec

  initialized: 18.236453 gbyte/sec
uninitialized: 19.056221 gbyte/sec

  initialized: 19.031227 gbyte/sec
uninitialized: 19.095597 gbyte/sec

  initialized: 18.930818 gbyte/sec
uninitialized: 19.163909 gbyte/sec

  initialized: 19.087323 gbyte/sec
uninitialized: 18.628657 gbyte/sec

  initialized: 15.600519 gbyte/sec
uninitialized: 14.116028 gbyte/sec

  initialized: 17.734223 gbyte/sec
uninitialized: 18.078878 gbyte/sec

  initialized: 17.958758 gbyte/sec
uninitialized: 18.127636 gbyte/sec

  initialized: 17.698652 gbyte/sec
uninitialized: 17.600630 gbyte/sec

  initialized: 16.234026 gbyte/sec
uninitialized: 17.218438 gbyte/sec

  initialized: 15.787085 gbyte/sec
uninitialized: 17.108970 gbyte/sec

  initialized: 16.694120 gbyte/sec
uninitialized: 18.280093 gbyte/sec

  initialized: 17.458720 gbyte/sec
uninitialized: 18.080837 gbyte/sec

  initialized: 18.981414 gbyte/sec
uninitialized: 18.954608 gbyte/sec

  initialized: 18.905466 gbyte/sec
uninitialized: 19.091459 gbyte/sec

  initialized: 17.182292 gbyte/sec
uninitialized: 17.376045 gbyte/sec

  initialized: 17.902690 gbyte/sec
uninitialized: 18.308555 gbyte/sec

  initialized: 18.276845 gbyte/sec
uninitialized: 17.495915 gbyte/sec

  initialized: 17.956093 gbyte/sec
uninitialized: 17.771114 gbyte/sec

  initialized: 17.729922 gbyte/sec
uninitialized: 18.586857 gbyte/sec

  initialized: 19.000266 gbyte/sec
uninitialized: 18.963647 gbyte/sec

  initialized: 19.139335 gbyte/sec
uninitialized: 19.112209 gbyte/sec

  initialized: 18.389100 gbyte/sec
uninitialized: 16.039853 gbyte/sec

  initialized: 17.719627 gbyte/sec
uninitialized: 18.494535 gbyte/sec

  initialized: 18.607230 gbyte/sec
uninitialized: 19.076535 gbyte/sec

  initialized: 19.090377 gbyte/sec
uninitialized: 18.488484 gbyte/sec

  initialized: 18.559148 gbyte/sec
uninitialized: 18.233608 gbyte/sec

  initialized: 17.826101 gbyte/sec
uninitialized: 16.632284 gbyte/sec

  initialized: 18.648696 gbyte/sec
uninitialized: 18.188398 gbyte/sec

  initialized: 18.939333 gbyte/sec
uninitialized: 19.041457 gbyte/sec

  initialized: 17.725239 gbyte/sec
uninitialized: 15.884636 gbyte/sec

  initialized: 15.685009 gbyte/sec
uninitialized: 16.608632 gbyte/sec

  initialized: 18.995560 gbyte/sec
uninitialized: 19.097592 gbyte/sec

  initialized: 18.661215 gbyte/sec
uninitialized: 19.150984 gbyte/sec

  initialized: 19.034580 gbyte/sec
uninitialized: 19.109339 gbyte/sec

  initialized: 19.138120 gbyte/sec
uninitialized: 19.109382 gbyte/sec

  initialized: 18.466187 gbyte/sec
uninitialized: 18.502004 gbyte/sec

  initialized: 18.595206 gbyte/sec
uninitialized: 16.578725 gbyte/sec

  initialized: 18.764862 gbyte/sec
uninitialized: 19.051762 gbyte/sec

  initialized: 19.022334 gbyte/sec
uninitialized: 19.140316 gbyte/sec

  initialized: 19.037047 gbyte/sec
uninitialized: 19.154422 gbyte/sec

  initialized: 19.149832 gbyte/sec
uninitialized: 19.040824 gbyte/sec

  initialized: 19.137672 gbyte/sec
uninitialized: 19.170773 gbyte/sec

  initialized: 19.145883 gbyte/sec
uninitialized: 19.107703 gbyte/sec

  initialized: 19.151518 gbyte/sec
uninitialized: 19.159591 gbyte/sec

  initialized: 19.080306 gbyte/sec
uninitialized: 18.035245 gbyte/sec

  initialized: 17.319097 gbyte/sec
uninitialized: 18.389729 gbyte/sec

  initialized: 17.805889 gbyte/sec
uninitialized: 19.042112 gbyte/sec

  initialized: 19.082468 gbyte/sec
uninitialized: 19.020439 gbyte/sec

  initialized: 19.024209 gbyte/sec
uninitialized: 19.116696 gbyte/sec

  initialized: 19.142577 gbyte/sec
uninitialized: 19.156301 gbyte/sec

  initialized: 19.149106 gbyte/sec
uninitialized: 19.159634 gbyte/sec

  initialized: 19.094684 gbyte/sec
uninitialized: 19.173490 gbyte/sec

  initialized: 19.089380 gbyte/sec
uninitialized: 19.170581 gbyte/sec

  initialized: 19.132941 gbyte/sec
uninitialized: 18.994636 gbyte/sec

  initialized: 18.631890 gbyte/sec
uninitialized: 18.589834 gbyte/sec