fork download
  1. #include<iostream>
  2. #include<random>
  3. #include<time.h>
  4. #include<vector>
  5. #include<cmath>
  6. #include<cstdio>
  7. using namespace std;
  8.  
  9. float time(int n){
  10. vector<vector<int >> A(n, vector<int>(n,0));
  11. vector<int> v(n,0);
  12. vector<int> m(n,0);
  13.  
  14. for(int i=0; i<n; i++){
  15. for(int j=0; j<n; j++){
  16. A[i][j]=rand();
  17. }
  18. v[i]=rand();
  19. }
  20.  
  21. clock_t t;
  22. t= clock();
  23.  
  24. for(int i=0; i<n; i++){
  25. for(int j=0; j<n; j++){
  26. m[i]+= A[i][j]*v[j];
  27. }
  28. }
  29. t= clock()-t;
  30. //printf("operations took %ld clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  31. return (((float)t)/CLOCKS_PER_SEC);
  32. }
  33.  
  34. vector<float> t(5,0);
  35. int main(){
  36. for(int i=256; i<5000; i=i*2){
  37. int k= i/256;
  38. int j= log2(k);
  39. t[j] = time(i);
  40. }
  41. FILE* gp = popen("gnuplot -persistent", "w");
  42.  
  43. fprintf(gp, "set title 'operational time vs n'\n");
  44. fprintf(gp, "set xlabel 'order of matrix- n'\n");
  45. fprintf(gp, "set ylabel 'time taken(s)'\n");
  46. fprintf(gp, "plot '-' with lines title 'time(s)'\n");
  47.  
  48. for (double x = 0; x < 5; x ++) {
  49. fprintf(gp, "%f %f\n", (256*pow(2,x)), t[x]);
  50. }
  51.  
  52. fprintf(gp, "e\n"); // end of data
  53. fflush(gp);
  54. pclose(gp);
  55. return 0;
  56.  
  57. }
Success #stdin #stdout #stderr 0.32s 68896KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
sh: 1: gnuplot: not found