📄 operatorbenchmark.java
字号:
}
report("int = int * int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 *= 2;
stopTimer(cnt, ii);
}
report("int *= 2");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 <<= 1;
stopTimer(cnt, ii);
}
report("int <<= 1");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 %= i2;
stopTimer(cnt, ii);
}
report("int %= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 = (i2 % i3);
stopTimer(cnt, ii);
}
report("int = int % int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 /= i2;
stopTimer(cnt, ii);
}
report("int /= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 = (i2 / i3);
stopTimer(cnt, ii);
}
report("int = int / int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 /= 2;
stopTimer(cnt, ii);
}
report("int /= 2");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 >>= 1;
stopTimer(cnt, ii);
}
report("int >>= 1");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 >>= i2;
stopTimer(cnt, ii);
}
report("int >>= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 = i2 >> i3;
stopTimer(cnt, ii);
}
report("int = int >> int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 |= i2;
stopTimer(cnt, ii);
}
report("int |= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 = i2 | i3;
stopTimer(cnt, ii);
}
report("int = int | int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 &= i2;
stopTimer(cnt, ii);
}
report("int &= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 = i2 & i3;
stopTimer(cnt, ii);
}
report("int = int & int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 ^= i2;
stopTimer(cnt, ii);
}
report("int ^= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
i1 = i2 ^ i3;
stopTimer(cnt, ii);
}
report("int = int ^ int");
println("--- long operators, local vars");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1++;
stopTimer(cnt, ii);
}
report("long++");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 += l2;
stopTimer(cnt, ii);
}
report("long += long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = (l2 + l3);
stopTimer(cnt, ii);
}
report("long = long + long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 *= l2;
stopTimer(cnt, ii);
}
report("long *= long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = (l2 * l3);
stopTimer(cnt, ii);
}
report("long = long * long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 *= 2;
stopTimer(cnt, ii);
}
report("long *= 2");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 <<= 1;
stopTimer(cnt, ii);
}
report("long <<= 1");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 %= l2;
stopTimer(cnt, ii);
}
report("long %= long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = (l2 % l3);
stopTimer(cnt, ii);
}
report("long = long % long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 /= l2;
stopTimer(cnt, ii);
}
report("long /= long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = (l2 / l3);
stopTimer(cnt, ii);
}
report("long = long / long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 /= 2;
stopTimer(cnt, ii);
}
report("long /= 2");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 >>= 1;
stopTimer(cnt, ii);
}
report("long >>= 1");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 >>= i2;
stopTimer(cnt, ii);
}
report("long >>= int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = l2 >> i3;
stopTimer(cnt, ii);
}
report("long = long >> int");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 |= l2;
stopTimer(cnt, ii);
}
report("long |= long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = l2 | l3;
stopTimer(cnt, ii);
}
report("long = long | long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 &= l2;
stopTimer(cnt, ii);
}
report("long &= long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = l2 & l3;
stopTimer(cnt, ii);
}
report("long = long & long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 ^= l2;
stopTimer(cnt, ii);
}
report("long ^= long");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
l1 = l2 ^ l3;
stopTimer(cnt, ii);
}
report("long = long ^ long");
println("--- float operators, local vars");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 += f2;
stopTimer(cnt, ii);
}
report("float += float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 = (float) (f2 + f3);
stopTimer(cnt, ii);
}
report("float = float + float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 *= f2;
stopTimer(cnt, ii);
}
report("float *= float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 = (float) (f2 * f3);
stopTimer(cnt, ii);
}
report("float = float * float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 %= f2;
stopTimer(cnt, ii);
}
report("float %= float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 = (float) (f2 % f3);
stopTimer(cnt, ii);
}
report("float = float % float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 /= f2;
stopTimer(cnt, ii);
}
report("float /= float");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
f1 = (float) (f2 / f3);
stopTimer(cnt, ii);
}
report("float = float / float");
println("--- double operators, local vars");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 += d2;
stopTimer(cnt, ii);
}
report("double += double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 = (d2 + d3);
stopTimer(cnt, ii);
}
report("double = double + double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 *= d2;
stopTimer(cnt, ii);
}
report("double *= double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 = (d2 * d3);
stopTimer(cnt, ii);
}
report("double = double * double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 %= d2;
stopTimer(cnt, ii);
}
report("double %= double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 = (d2 % d3);
stopTimer(cnt, ii);
}
report("double = double % double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 /= d2;
stopTimer(cnt, ii);
}
report("double /= double");
for (cnt = getSampleCount(); --cnt >= 0; ) {
startTimer(true);
for (ii = 0; go; ii++)
d1 = (d2 / d3);
stopTimer(cnt, ii);
}
report("double = double / double");
useint[0] = dummy1; useint[1] = dummy2; useint[2] = dummy3;
return finishTest();
}
} // class OperatorBenchmark
// EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -