(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.test00org0thrpt12291.113±23.547ops/usMyBenchmark.test00org1431306240thrpt12241.898±11.175ops/usMyBenchmark.test00org1431655424thrpt12237.664±19.245ops/usMyBenchmark.test00org1073741824thrpt12230.101±24.000ops/usMyBenchmark.test010thrpt12283.717±22.913ops/usMyBenchmark.test011431306240thrpt12267.750±13.008ops/usMyBenchmark.test011431655424thrpt12268.527±8.443ops/usMyBenchmark.test011073741824thrpt12260.763±6.061ops/usMyBenchmark.test020thrpt12293.646±14.304ops/usMyBenchmark.test021431306240thrpt12261.271±13.394ops/usMyBenchmark.test021431655424thrpt12270.592±8.326ops/usMyBenchmark.test021073741824thrpt12256.464±6.505ops/usMyBenchmark.test030thrpt12193.403±11.293ops/usMyBenchmark.test031431306240thrpt12188.536±13.164ops/usMyBenchmark.test031431655424thrpt12193.128±12.082ops/usMyBenchmark.test031073741824thrpt12193.973±5.536ops/usMyBenchmark.test040thrpt12289.182±16.055ops/usMyBenchmark.test041431306240thrpt12193.120±9.813ops/usMyBenchmark.test041431655424thrpt12194.009±10.200ops/usMyBenchmark.test041073741824thrpt12190.462±8.510ops/usMyBenchmark.test050thrpt12275.133±13.173ops/usMyBenchmark.test051431306240thrpt12272.563±17.852ops/usMyBenchmark.test051431655424thrpt12275.591±10.857ops/usMyBenchmark.test051073741824thrpt12251.839±14.423ops/usMyBenchmark.testBase0thrpt12341.165±14.035ops/usMyBenchmark.testBase1431306240thrpt12335.527±13.656ops/usMyBenchmark.testBase1431655424thrpt12286.153±60.354ops/usMyBenchmark.testBase1073741824thrpt12309.770±44.231ops/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 291.113 ± 23.547 ops/us MyBenchmark.test00_org 1431306240 thrpt 12 241.898 ± 11.175 ops/us MyBenchmark.test00_org 1431655424 thrpt 12 237.664 ± 19.245 ops/us MyBenchmark.test00_org 1073741824 thrpt 12 230.101 ± 24.000 ops/us MyBenchmark.test01 0 thrpt 12 283.717 ± 22.913 ops/us MyBenchmark.test01 1431306240 thrpt 12 267.750 ± 13.008 ops/us MyBenchmark.test01 1431655424 thrpt 12 268.527 ± 8.443 ops/us MyBenchmark.test01 1073741824 thrpt 12 260.763 ± 6.061 ops/us MyBenchmark.test02 0 thrpt 12 293.646 ± 14.304 ops/us MyBenchmark.test02 1431306240 thrpt 12 261.271 ± 13.394 ops/us MyBenchmark.test02 1431655424 thrpt 12 270.592 ± 8.326 ops/us MyBenchmark.test02 1073741824 thrpt 12 256.464 ± 6.505 ops/us MyBenchmark.test03 0 thrpt 12 193.403 ± 11.293 ops/us MyBenchmark.test03 1431306240 thrpt 12 188.536 ± 13.164 ops/us MyBenchmark.test03 1431655424 thrpt 12 193.128 ± 12.082 ops/us MyBenchmark.test03 1073741824 thrpt 12 193.973 ± 5.536 ops/us MyBenchmark.test04 0 thrpt 12 289.182 ± 16.055 ops/us MyBenchmark.test04 1431306240 thrpt 12 193.120 ± 9.813 ops/us MyBenchmark.test04 1431655424 thrpt 12 194.009 ± 10.200 ops/us MyBenchmark.test04 1073741824 thrpt 12 190.462 ± 8.510 ops/us MyBenchmark.test05 0 thrpt 12 275.133 ± 13.173 ops/us MyBenchmark.test05 1431306240 thrpt 12 272.563 ± 17.852 ops/us MyBenchmark.test05 1431655424 thrpt 12 275.591 ± 10.857 ops/us MyBenchmark.test05 1073741824 thrpt 12 251.839 ± 14.423 ops/us MyBenchmark.testBase 0 thrpt 12 341.165 ± 14.035 ops/us MyBenchmark.testBase 1431306240 thrpt 12 335.527 ± 13.656 ops/us MyBenchmark.testBase 1431655424 thrpt 12 286.153 ± 60.354 ops/us MyBenchmark.testBase 1073741824 thrpt 12 309.770 ± 44.231 ops/us javaclientjartarget/benchmarks.jari6wi6f2tuusw1r1Benchmark(arg)ModeCntScoreErrorUnitsMyBenchmark.test00_org0thrpt12291.113±23.547ops/usMyBenchmark.test00_org1431306240thrpt12241.898±11.175ops/usMyBenchmark.test00_org1431655424thrpt12237.664±19.245ops/usMyBenchmark.test00_org1073741824thrpt12230.101±24.000ops/usMyBenchmark.test010thrpt12283.717±22.913ops/usMyBenchmark.test011431306240thrpt12267.750±13.008ops/usMyBenchmark.test011431655424thrpt12268.527±8.443ops/usMyBenchmark.test011073741824thrpt12260.763±6.061ops/usMyBenchmark.test020thrpt12293.646±14.304ops/usMyBenchmark.test021431306240thrpt12261.271±13.394ops/usMyBenchmark.test021431655424thrpt12270.592±8.326ops/usMyBenchmark.test021073741824thrpt12256.464±6.505ops/usMyBenchmark.test030thrpt12193.403±11.293ops/usMyBenchmark.test031431306240thrpt12188.536±13.164ops/usMyBenchmark.test031431655424thrpt12193.128±12.082ops/usMyBenchmark.test031073741824thrpt12193.973±5.536ops/usMyBenchmark.test040thrpt12289.182±16.055ops/usMyBenchmark.test041431306240thrpt12193.120±9.813ops/usMyBenchmark.test041431655424thrpt12194.009±10.200ops/usMyBenchmark.test041073741824thrpt12190.462±8.510ops/usMyBenchmark.test050thrpt12275.133±13.173ops/usMyBenchmark.test051431306240thrpt12272.563±17.852ops/usMyBenchmark.test051431655424thrpt12275.591±10.857ops/usMyBenchmark.test051073741824thrpt12251.839±14.423ops/usMyBenchmark.testBase0thrpt12341.165±14.035ops/usMyBenchmark.testBase1431306240thrpt12335.527±13.656ops/usMyBenchmark.testBase1431655424thrpt12286.153±60.354ops/usMyBenchmark.testBase1073741824thrpt12309.770±44.231ops/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 296.316 ± 8.520 ops/us MyBenchmark.test00_org 1431306240 thrpt 12 241.906 ± 11.665 ops/us MyBenchmark.test00_org 1431655424 thrpt 12 246.305 ± 7.969 ops/us MyBenchmark.test00_org 1073741824 thrpt 12 241.137 ± 11.528 ops/us MyBenchmark.test01 0 thrpt 12 299.702 ± 15.846 ops/us MyBenchmark.test01 1431306240 thrpt 12 280.038 ± 12.697 ops/us MyBenchmark.test01 1431655424 thrpt 12 274.764 ± 6.699 ops/us MyBenchmark.test01 1073741824 thrpt 12 256.021 ± 17.347 ops/us MyBenchmark.test02 0 thrpt 12 237.673 ± 78.720 ops/us MyBenchmark.test02 1431306240 thrpt 12 259.108 ± 10.610 ops/us MyBenchmark.test02 1431655424 thrpt 12 260.018 ± 8.225 ops/us MyBenchmark.test02 1073741824 thrpt 12 245.817 ± 18.844 ops/us MyBenchmark.test03 0 thrpt 12 192.881 ± 6.182 ops/us MyBenchmark.test03 1431306240 thrpt 12 191.576 ± 5.869 ops/us MyBenchmark.test03 1431655424 thrpt 12 192.481 ± 5.587 ops/us MyBenchmark.test03 1073741824 thrpt 12 191.741 ± 8.870 ops/us MyBenchmark.test04 0 thrpt 12 306.072 ± 14.152 ops/us MyBenchmark.test04 1431306240 thrpt 12 201.520 ± 5.274 ops/us MyBenchmark.test04 1431655424 thrpt 12 196.645 ± 8.344 ops/us MyBenchmark.test04 1073741824 thrpt 12 191.471 ± 5.082 ops/us MyBenchmark.test05 0 thrpt 12 274.795 ± 16.256 ops/us MyBenchmark.test05 1431306240 thrpt 12 263.954 ± 5.144 ops/us MyBenchmark.test05 1431655424 thrpt 12 261.575 ± 9.649 ops/us MyBenchmark.test05 1073741824 thrpt 12 246.987 ± 5.948 ops/us MyBenchmark.testBase 0 thrpt 12 341.527 ± 10.250 ops/us MyBenchmark.testBase 1431306240 thrpt 12 340.992 ± 17.565 ops/us MyBenchmark.testBase 1431655424 thrpt 12 342.035 ± 15.079 ops/us MyBenchmark.testBase 1073741824 thrpt 12 335.475 ± 16.870 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); } @Benchmark public int test05() { return numberOfTrailingZeros_05(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; } public static int numberOfTrailingZeros_05(int i) { return 32 - numberOfLeadingZeros(~i & (i - 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; } }