Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
virtual test
#include <iostream> #include <chrono> #include <vector> using namespace std; class B2{ public: virtual ~B2() = default; virtual int f(int n){return -n;} int g(int n){return -n;} }; class C : public B2{ public: int f(int n) override {return n;} }; int main() { std::vector<B2*> bs; const int numTest=1000000; for(int n=0;n<numTest;n++){ if(((double) rand() / (RAND_MAX))>0.5){ bs.push_back(new B2()); }else{ bs.push_back(new C()); } }; auto t1 = std::chrono::system_clock::now(); int s=0; for(int n=0;n<numTest;n++){ s+=bs[n]->f(n); }; auto t2= std::chrono::system_clock::now(); for(int n=0;n<numTest;n++){ s+=bs[n]->g(n); }; auto t3= std::chrono::system_clock::now(); auto t21=t2-t1; auto t32=t3-t2; std::cout<<t21.count()<<" "<<t32.count()<<" ratio="<< (((float)t21.count())/t32.count()) << std::endl; std::cout<<s<<std::endl; for(int n=0;n<numTest;n++){ delete bs[n]; }; }
run
|
edit
|
history
|
help
0
move swap
Two-phase sample with Visual C++ 2015
Affine Key Finder and Decrypter
Progress bar
wrong up
<string> Indirect include of <errno.h> with VSC++
MSVC C2888 bug
infix to postfix v 3.0
Not an overflow
timeConversion