Код #include <stdio.h> #include <conio.h> #include <windows.h> class A { public: double calculate(double p1, double p2) { return (p1 / p2)/(p1+p2); } }; int main() { printf("start...\n"); long t1 = GetTickCount(); double res = 0; for(int i = 0; i < 10000000; i++) { A *a = new A(); res += (a->calculate(i+1, 11)); delete a; } long t2 = GetTickCount() - t1; printf("res = %f, time = %i \n", res, t2); getch(); return 0; }
медленнее чем
public class NewClass { public NewClass() { } public static void main(String[] args) { System.out.println("start..."); double res = 0; long t1 = System.currentTimeMillis(); for(int i = 0; i < 10000000; i++) { res += (new A().calculate(i + 1, 11)); } long t2 = System.currentTimeMillis() - t1; System.out.println("res = " + res + " time = " + t2); } } class A { public double calculate(double p1, double p2) { return (p1 / p2)/(p1+p2); }