| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <vector> |
| 4 | |
| 5 | using namespace std; |
| 6 | |
| 7 | class Base { |
| 8 | public: |
| 9 | virtual int Foo() = 0; |
| 10 | }; |
| 11 | |
| 12 | class Derived1 : public Base { |
| 13 | public: |
| 14 | int Foo() override { return 1; } |
| 15 | }; |
| 16 | |
| 17 | class Derived2 : public Base { |
| 18 | public: |
| 19 | int Foo() override { return 2; } |
| 20 | }; |
| 21 | |
| 22 | class Derived3 : public Base { |
| 23 | public: |
| 24 | int Foo() override { return 3; } |
| 25 | }; |
| 26 | |
| 27 | int main(int argc, char *argv[]) { |
| 28 | long long sum = 0; |
| 29 | int outerIters = atoi(nptr: argv[1]); |
| 30 | int selector = atoi(nptr: argv[2]); |
| 31 | |
| 32 | Base *obj1 = new Derived1(); |
| 33 | Base *obj2 = new Derived2(); |
| 34 | Base *obj3 = new Derived3(); |
| 35 | |
| 36 | for (int j = 0; j < outerIters; j++) { |
| 37 | for (int i = 0; i < 10000; i++) { |
| 38 | switch (selector) { |
| 39 | case 1: sum += obj1->Foo(); break; |
| 40 | case 2: sum += obj2->Foo(); break; |
| 41 | case 3: sum += obj3->Foo(); break; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | printf(format: "%lld\n" , sum); |
| 46 | } |
| 47 | |