/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package org.openjdk.bench.vm.compiler;
drLongValues1 = newlong[ARRAYSIZE];
drLongValues2 = newlong[ARRAYSIZE];
drLongValuesAsInts1 = newlong[ARRAYSIZE];
drLongValuesAsInts2 = newlong[ARRAYSIZE]; for (int i = 0; i < ARRAYSIZE; i++) { long l = r.nextLong(); if (l == 0L) {
l++;
}
drLongValues1[i] = l;
drLongValuesAsInts1[i] = (long) (int) l;
l = r.nextLong(); if (l == 0L) {
l++;
}
drLongValues2[i] = l;
drLongValuesAsInts2[i] = (long) (int) l;
}
}
/** * Tests integer division with a constant divisor. Hopefully the JVM will do a Granlund-Montgomery and convert it to * a multiplication instead.
*/
@Benchmark publicint testIntDivConstantDivisor() { int dummy = 0; for (int i = 0; i < intValues.length; i++) {
dummy += intValues[i] / 49;
} return dummy;
}
/** * Tests long division with a constant divisor. Hopefully the JVM will do a Granlund-Montgomery and convert it to a * multiplication instead.
*/
@Benchmark publiclong testLongDivConstantDivisor() { long dummy = 0; for (int i = 0; i < longValues.length; i++) {
dummy += longValues[i] / 49L + longValues[i] / 0x4949494949L;
} return dummy;
}
/** * Tests integer remainder with a constant divisor. Hopefully the JVM will do a Granlund-Montgomery and convert it to * two multiplications instead.
*/
@Benchmark publicint testIntRemConstantDivisor() { int dummy = 0; for (int i = 0; i < intValues.length; i++) {
dummy += intValues[i] % 49;
} return dummy;
}
/** * Tests long division with a constant divisor. Hopefully the JVM will do a Granlund-Montgomery and convert it to a * multiplication instead.
*/
@Benchmark publiclong testLongRemConstantDivisor() { long dummy = 0; for (int i = 0; i < longValues.length; i++) {
dummy += longValues[i] % 49L + longValues[i] % 0x4949494949L;
} return dummy;
}
/** * Tests integer division with a variable divisor. This benchmark is mainly here to be a comparison against the * benchmark that performs both divisions and remainder calculations.
*/
@Benchmark publicint testIntDivVariableDivisor() { int dummy = 0; for (int i = 0; i < intValues.length; i++) {
dummy += intValues2[i] / intValues[i];
} return dummy;
}
/** * Tests integer division and remainder with a variable divisor. Both calculations are performed with the same * divisor, so a JVM should not have to perform two complex calculations. Either a division followed by a * multiplication, or on X86 using idiv, where the reminder is also returned from the idiv instruction.
*/
@Benchmark publicint testIntDivRemVariableDivisor() { int dummy = 0; for (int i = 0; i < intValues.length; i++) {
dummy += intValues2[i] / intValues[i];
dummy += intValues2[i] % intValues[i];
} return dummy;
}
@Benchmark publiclong test64DivRem64() { long dummy = 0; for (int i = 0; i < drLongValues1.length; i++) { long l1 = drLongValues1[i]; long l2 = drLongValues2[i];
dummy += l1 / l2;
dummy += l1 % l2;
} return dummy;
}
@Benchmark publiclong test32DivRem32() { long dummy = 0; for (int i = 0; i < drLongValuesAsInts1.length; i++) { long l1 = drLongValuesAsInts1[i]; long l2 = drLongValuesAsInts2[i];
dummy += l1 / l2;
dummy += l1 % l2;
} return dummy;
}
@Benchmark publiclong test64DivRem32() { long dummy = 0; for (int i = 0; i < drLongValues1.length; i++) { long l1 = drLongValues1[i]; long l2 = drLongValuesAsInts2[i];
dummy += l1 / l2;
dummy += l1 % l2;
} return dummy;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.