(original) (raw)
/* tested with java 12-ea 2019-03-19 Java(TM) SE Runtime Environment 19.3 (build 12-ea+5) Java HotSpot(TM) 64-Bit Server VM 19.3 (build 12-ea+5, mixed mode) java−client−jartarget/benchmarks.jar−i6−wi6−f2−tuus−w1−r1Benchmark(arg)ModeCntScoreErrorUnitsMyBenchmark.test00org0thrpt12286.288±11.985ops/usMyBenchmark.test00org1431306240thrpt12212.825±28.020ops/usMyBenchmark.test00org1431655424thrpt12226.959±18.117ops/usMyBenchmark.test00org1073741824thrpt12229.595±16.844ops/usMyBenchmark.test010thrpt12271.913±13.536ops/usMyBenchmark.test011431306240thrpt12257.550±27.689ops/usMyBenchmark.test011431655424thrpt12255.681±14.725ops/usMyBenchmark.test011073741824thrpt12251.115±18.688ops/usMyBenchmark.test020thrpt12293.080±20.000ops/usMyBenchmark.test021431306240thrpt12262.839±9.720ops/usMyBenchmark.test021431655424thrpt12259.414±8.313ops/usMyBenchmark.test021073741824thrpt12246.837±7.973ops/usMyBenchmark.test030thrpt12184.142±6.984ops/usMyBenchmark.test031431306240thrpt12191.057±11.898ops/usMyBenchmark.test031431655424thrpt12182.586±8.737ops/usMyBenchmark.test031073741824thrpt12163.746±51.411ops/usMyBenchmark.test040thrpt12280.672±32.949ops/usMyBenchmark.test041431306240thrpt12182.571±9.342ops/usMyBenchmark.test041431655424thrpt12185.054±5.169ops/usMyBenchmark.test041073741824thrpt12184.751±34.924ops/usMyBenchmark.testBase0thrpt12311.156±16.749ops/usMyBenchmark.testBase1431306240thrpt12334.265±14.190ops/usMyBenchmark.testBase1431655424thrpt12309.225±32.727ops/usMyBenchmark.testBase1073741824thrpt12316.688±9.527ops/usjava -client -jar target/benchmarks.jar -i 6 -wi 6 -f 2 -tu us -w 1 -r 1 Benchmark (arg) Mode Cnt Score Error Units MyBenchmark.test00_org 0 thrpt 12 286.288 ± 11.985 ops/us MyBenchmark.test00_org 1431306240 thrpt 12 212.825 ± 28.020 ops/us MyBenchmark.test00_org 1431655424 thrpt 12 226.959 ± 18.117 ops/us MyBenchmark.test00_org 1073741824 thrpt 12 229.595 ± 16.844 ops/us MyBenchmark.test01 0 thrpt 12 271.913 ± 13.536 ops/us MyBenchmark.test01 1431306240 thrpt 12 257.550 ± 27.689 ops/us MyBenchmark.test01 1431655424 thrpt 12 255.681 ± 14.725 ops/us MyBenchmark.test01 1073741824 thrpt 12 251.115 ± 18.688 ops/us MyBenchmark.test02 0 thrpt 12 293.080 ± 20.000 ops/us MyBenchmark.test02 1431306240 thrpt 12 262.839 ± 9.720 ops/us MyBenchmark.test02 1431655424 thrpt 12 259.414 ± 8.313 ops/us MyBenchmark.test02 1073741824 thrpt 12 246.837 ± 7.973 ops/us MyBenchmark.test03 0 thrpt 12 184.142 ± 6.984 ops/us MyBenchmark.test03 1431306240 thrpt 12 191.057 ± 11.898 ops/us MyBenchmark.test03 1431655424 thrpt 12 182.586 ± 8.737 ops/us MyBenchmark.test03 1073741824 thrpt 12 163.746 ± 51.411 ops/us MyBenchmark.test04 0 thrpt 12 280.672 ± 32.949 ops/us MyBenchmark.test04 1431306240 thrpt 12 182.571 ± 9.342 ops/us MyBenchmark.test04 1431655424 thrpt 12 185.054 ± 5.169 ops/us MyBenchmark.test04 1073741824 thrpt 12 184.751 ± 34.924 ops/us MyBenchmark.testBase 0 thrpt 12 311.156 ± 16.749 ops/us MyBenchmark.testBase 1431306240 thrpt 12 334.265 ± 14.190 ops/us MyBenchmark.testBase 1431655424 thrpt 12 309.225 ± 32.727 ops/us MyBenchmark.testBase 1073741824 thrpt 12 316.688 ± 9.527 ops/us java−client−jartarget/benchmarks.jar−i6−wi6−f2−tuus−w1−r1Benchmark(arg)ModeCntScoreErrorUnitsMyBenchmark.test00_org0thrpt12286.288±11.985ops/usMyBenchmark.test00_org1431306240thrpt12212.825±28.020ops/usMyBenchmark.test00_org1431655424thrpt12226.959±18.117ops/usMyBenchmark.test00_org1073741824thrpt12229.595±16.844ops/usMyBenchmark.test010thrpt12271.913±13.536ops/usMyBenchmark.test011431306240thrpt12257.550±27.689ops/usMyBenchmark.test011431655424thrpt12255.681±14.725ops/usMyBenchmark.test011073741824thrpt12251.115±18.688ops/usMyBenchmark.test020thrpt12293.080±20.000ops/usMyBenchmark.test021431306240thrpt12262.839±9.720ops/usMyBenchmark.test021431655424thrpt12259.414±8.313ops/usMyBenchmark.test021073741824thrpt12246.837±7.973ops/usMyBenchmark.test030thrpt12184.142±6.984ops/usMyBenchmark.test031431306240thrpt12191.057±11.898ops/usMyBenchmark.test031431655424thrpt12182.586±8.737ops/usMyBenchmark.test031073741824thrpt12163.746±51.411ops/usMyBenchmark.test040thrpt12280.672±32.949ops/usMyBenchmark.test041431306240thrpt12182.571±9.342ops/usMyBenchmark.test041431655424thrpt12185.054±5.169ops/usMyBenchmark.test041073741824thrpt12184.751±34.924ops/usMyBenchmark.testBase0thrpt12311.156±16.749ops/usMyBenchmark.testBase1431306240thrpt12334.265±14.190ops/usMyBenchmark.testBase1431655424thrpt12309.225±32.727ops/usMyBenchmark.testBase1073741824thrpt12316.688±9.527ops/usjava -server -jar target/benchmarks.jar -i 6 -wi 6 -f 2 -tu us -w 1 -r 1 Benchmark (arg) Mode Cnt Score Error Units MyBenchmark.test00_org 0 thrpt 12 289.942 ± 20.372 ops/us MyBenchmark.test00_org 1431306240 thrpt 12 232.692 ± 13.149 ops/us MyBenchmark.test00_org 1431655424 thrpt 12 231.487 ± 10.698 ops/us MyBenchmark.test00_org 1073741824 thrpt 12 230.005 ± 7.881 ops/us MyBenchmark.test01 0 thrpt 12 263.401 ± 11.880 ops/us MyBenchmark.test01 1431306240 thrpt 12 214.299 ± 74.813 ops/us MyBenchmark.test01 1431655424 thrpt 12 257.942 ± 14.017 ops/us MyBenchmark.test01 1073741824 thrpt 12 250.657 ± 16.509 ops/us MyBenchmark.test02 0 thrpt 12 266.900 ± 25.503 ops/us MyBenchmark.test02 1431306240 thrpt 12 249.002 ± 13.897 ops/us MyBenchmark.test02 1431655424 thrpt 12 247.914 ± 15.950 ops/us MyBenchmark.test02 1073741824 thrpt 12 233.352 ± 32.603 ops/us MyBenchmark.test03 0 thrpt 12 187.445 ± 9.653 ops/us MyBenchmark.test03 1431306240 thrpt 12 190.762 ± 10.100 ops/us MyBenchmark.test03 1431655424 thrpt 12 191.753 ± 13.462 ops/us MyBenchmark.test03 1073741824 thrpt 12 177.514 ± 11.500 ops/us MyBenchmark.test04 0 thrpt 12 239.656 ± 17.210 ops/us MyBenchmark.test04 1431306240 thrpt 12 172.113 ± 7.622 ops/us MyBenchmark.test04 1431655424 thrpt 12 165.078 ± 11.616 ops/us MyBenchmark.test04 1073741824 thrpt 12 172.641 ± 9.023 ops/us MyBenchmark.testBase 0 thrpt 12 284.883 ± 45.945 ops/us MyBenchmark.testBase 1431306240 thrpt 12 309.343 ± 25.788 ops/us MyBenchmark.testBase 1431655424 thrpt 12 300.599 ± 17.094 ops/us MyBenchmark.testBase 1073741824 thrpt 12 307.664 ± 22.260 ops/us */ /* * Copyright (c) 2014, Oracle America, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Oracle nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ package org.sample; import org.openjdk.jmh.annotations.*; @State(Scope.Benchmark) public class MyBenchmark { @Param({"0", "1431306240", "1431655424", "1073741824"}) public int arg; @Benchmark public int testBase() { return arg; } @Benchmark public int test00_org() { return numberOfTrailingZeros_00_org(arg); } @Benchmark public int test01() { return numberOfTrailingZeros_01(arg); } @Benchmark public int test02() { return numberOfTrailingZeros_02(arg); } @Benchmark public int test03() { return numberOfTrailingZeros_03(arg); } @Benchmark public int test04() { return numberOfTrailingZeros_04(arg); } static int numberOfTrailingZeros_00_org(int i) { // HD, Figure 5-14 int y; if (i == 0) return 32; int n = 31; y = i <<16; if (y != 0) { n = n -16; i = y; } y = i << 8; if (y != 0) { n = n - 8; i = y; } y = i << 4; if (y != 0) { n = n - 4; i = y; } y = i << 2; if (y != 0) { n = n - 2; i = y; } return n - ((i << 1) >>> 31); } static int numberOfTrailingZeros_01(int i) { i &= -i; // lowest one bit if (i <= 0) return i == 0 ? 32 : 31; int n = -1; if (i >= 1 << 16) { n += 16; i >>>= 16; } if (i >= 1 << 8) { n += 8; i >>>= 8; } if (i >= 1 << 4) { n += 4; i >>>= 4; } if (i >= 1 << 2) { n += 2; i >>>= 2; } return n + i; } static int numberOfTrailingZeros_02(int i) { if (i == 0) return 32; return 31 - numberOfLeadingZeros(i & -i); } static int numberOfTrailingZeros_03(int i) { return bitCount(~i & (i - 1)); } static int numberOfTrailingZeros_04(int i) { if (i == 0) return 32; return bitCount(i ^ (i - 1)) - 1; } static int numberOfLeadingZeros(int i) { // HD, Count leading 0's if (i <= 0) return i == 0 ? 32 : 0; int n = 31; if (i >= 1 << 16) { n -= 16; i >>>= 16; } if (i >= 1 << 8) { n -= 8; i >>>= 8; } if (i >= 1 << 4) { n -= 4; i >>>= 4; } if (i >= 1 << 2) { n -= 2; i >>>= 2; } return n - (i >>> 1); } static int bitCount(int i) { // HD, Figure 5-2 i = i - ((i >>> 1) & 0x55555555); i = (i & 0x33333333) + ((i >>> 2) & 0x33333333); i = (i + (i >>> 4)) & 0x0f0f0f0f; i = i + (i >>> 8); i = i + (i >>> 16); return i & 0x3f; } }