Код: Выделить всё
#include
#include
unsigned long long s(unsigned long long n)
{
unsigned long long s = 0;
for (unsigned long long i = 0; i < n; i++)
s += i;
return s;
}
int main()
{
LARGE_INTEGER freq, start, end;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
printf("%llu\n", s(1000000000));
QueryPerformanceCounter(&end);
double d = (double) (end.QuadPart - start.QuadPart) / freq.QuadPart * 1000.0;
printf("Delta: %f\n", d);
return 0;
}
< /code>
java -код: < /p>
public class JavaApplication5 {
public static long s(long n) {
long s = 0;
for (long i = 0; i < n; i++) {
s += i;
}
return s;
}
public static void main(String[] args) {
long start = System.nanoTime();
System.out.println(s(1000000000));
long end = System.nanoTime();
System.out.println((end - start)/1000000);
}
}
Код: Выделить всё
Java: 2795 msКод: Выделить всё
C++ : 0.013517 msэто говорит, что C ++ в 206777 раза быстрее, чем Java! Ни за что! Что не так в моем тесте? Разница огромна.
Подробнее здесь: https://stackoverflow.com/questions/757 ... ic-results
Мобильная версия