Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
int cnt = 10000;
int top = 262144;
long time = System.currentTimeMillis();
for (int i = 0; i < cnt; i++) {
int delim = 1;
for (int j = 1; j < top; j++)
if (top % j == 0)
delim = j;
}
time = System.currentTimeMillis() - time;
System.out.println("Average execution time: " + ((float) time / cnt) + " ms");Average execution time: 0.0766 msint cnt = 10000;
int top = 262144;
long time = System.currentTimeMillis();
int uselessVar = 0;
for (int i = 0; i < cnt; i++) {
int delim = 1;
for (int j = top - 1; j > 0; j--)
if (top % j == 0) {
delim = j;
break;
}
uselessVar += delim;
}
time = System.currentTimeMillis() - time;
System.out.println("Value of useless var: " + uselessVar);
System.out.println("Average execution time: " + ((float) time / cnt) + " ms");
Value of useless var: 1310720000
Average execution time: 0.387 ms
(function(){
var startDate = +new Date(), i, cnt, result;
for( cnt = 0; cnt < 1000; cnt++ )
for( i = 262144; --i;)
if( 262144 % i === 0 ){
result = i;
break;
}
console.log(result);
console.log((+new Date() - startDate)/cnt);
})();
module Main where
top = 262144
main = putStrLn $ show $ findDelim top (top - 1)
findDelim num delim
| (mod num delim) == 0 = delim
| otherwise = findDelim num (delim - 1)
Манчестерской малой экспериментальной машине — 65 лет