Используйте clock() для определения стоимости (1) функционального вызова, (2) вызова виртуальной функции, (3) чтения char, (4) чтение int из одной цифры, (5) чтение int из пяти цифр, (6) чтение double из пяти цифр, (7) односимвольного string, (8) пятисимвольного string и (9) сорокасимвольного string.
Ну в вобщем от что то вроде этого должно получиться:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#include <iostream> using std::cout; using std::endl; #include <ctime> #include <iomanip> using std::setprecision; using std::setw; #include <string> using std::string; void f(){cout <<"mu tyt"<<endl;} class A { public: virtual void draw(){cout <<"Hellow world"<<endl;} }; class B:public A {}; int main() { clock_t beg,end; float rez; //для функционального вызова beg=clock(); f(); end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez1= "<<setw(20)<<setprecision(20)<<rez<<endl; //для виртуальной функции B bb; beg=clock(); bb.draw(); end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez2= "<<setw(20)<<setprecision(20)<<rez<<endl; //чтение char beg=clock(); char c='3'; cout <<"c= "<<c<<endl; end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez3= "<<setw(20)<<setprecision(20)<<rez<<endl; //чтение int из одной цифры beg=clock(); int n=1; cout <<"n= "<<n<<endl; end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez4= "<<setw(20)<<setprecision(20)<<rez<<endl; //чтение int из 5 цифр beg=clock(); int n5=33333; cout <<"n5= "<<n5<<endl; end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez5= "<<setw(20)<<setprecision(20)<<rez<<endl; //Чтение double из 5 цифр beg=clock(); bb.draw(); end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez6= "<<setw(20)<<setprecision(20)<<rez<<endl; //чтение односимвольного string beg=clock(); string ss="h"; cout <<"ss= "<<ss<<endl; end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez7= "<<setw(20)<<setprecision(20)<<rez<<endl; //чтение 5-символьного string beg=clock(); string ss5="hello"; cout <<"ss5= "<<ss5<<endl; end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez2= "<<setw(20)<<setprecision(20)<<rez<<endl; //чтение 40-символьного string beg=clock(); string ss40="hellow world gacpada da dad ad ad adlfkasdlkfjasdl fksa flkask dfjaslkfsad lkf asdddklf"; cout <<"ss40= "<<ss40<<endl; end=clock()-beg; rez=(float)end/CLOCKS_PER_SEC; cout <<"rez2= "<<setw(20)<<setprecision(20)<<rez<<endl; return 0; } |
[youtube]https://www.youtube.com/watch?v=oLj4E8DHC1s[/youtube]