(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.test00org0thrpt12279.741±29.887ops/usMyBenchmark.test00org3062447746611937280thrpt12205.673±7.439ops/usMyBenchmark.test00org3074515986238406656thrpt12201.798±6.953ops/usMyBenchmark.test00org3074457344191496192thrpt12190.171±39.043ops/usMyBenchmark.test010thrpt12202.220±73.463ops/usMyBenchmark.test013062447746611937280thrpt12236.309±8.704ops/usMyBenchmark.test013074515986238406656thrpt12237.174±23.063ops/usMyBenchmark.test013074457344191496192thrpt12242.547±13.411ops/usMyBenchmark.test020thrpt12299.377±10.452ops/usMyBenchmark.test023062447746611937280thrpt12206.543±8.674ops/usMyBenchmark.test023074515986238406656thrpt12210.015±14.216ops/usMyBenchmark.test023074457344191496192thrpt12206.154±9.162ops/usMyBenchmark.test030thrpt12282.034±12.122ops/usMyBenchmark.test033062447746611937280thrpt12253.645±17.289ops/usMyBenchmark.test033074515986238406656thrpt12252.782±15.609ops/usMyBenchmark.test033074457344191496192thrpt12243.416±18.441ops/usMyBenchmark.test040thrpt12165.815±4.197ops/usMyBenchmark.test043062447746611937280thrpt12163.729±5.918ops/usMyBenchmark.test043074515986238406656thrpt12164.267±7.493ops/usMyBenchmark.test043074457344191496192thrpt12164.083±9.870ops/usMyBenchmark.test050thrpt12297.639±13.674ops/usMyBenchmark.test053062447746611937280thrpt12212.426±9.613ops/usMyBenchmark.test053074515986238406656thrpt12212.237±11.419ops/usMyBenchmark.test053074457344191496192thrpt12225.235±5.499ops/usMyBenchmark.testBase0thrpt12327.570±14.005ops/usMyBenchmark.testBase3062447746611937280thrpt12340.888±26.225ops/usMyBenchmark.testBase3074515986238406656thrpt12347.679±13.391ops/usMyBenchmark.testBase3074457344191496192thrpt12334.544±18.950ops/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 279.741 ± 29.887 ops/us MyBenchmark.test00_org 3062447746611937280 thrpt 12 205.673 ± 7.439 ops/us MyBenchmark.test00_org 3074515986238406656 thrpt 12 201.798 ± 6.953 ops/us MyBenchmark.test00_org 3074457344191496192 thrpt 12 190.171 ± 39.043 ops/us MyBenchmark.test01 0 thrpt 12 202.220 ± 73.463 ops/us MyBenchmark.test01 3062447746611937280 thrpt 12 236.309 ± 8.704 ops/us MyBenchmark.test01 3074515986238406656 thrpt 12 237.174 ± 23.063 ops/us MyBenchmark.test01 3074457344191496192 thrpt 12 242.547 ± 13.411 ops/us MyBenchmark.test02 0 thrpt 12 299.377 ± 10.452 ops/us MyBenchmark.test02 3062447746611937280 thrpt 12 206.543 ± 8.674 ops/us MyBenchmark.test02 3074515986238406656 thrpt 12 210.015 ± 14.216 ops/us MyBenchmark.test02 3074457344191496192 thrpt 12 206.154 ± 9.162 ops/us MyBenchmark.test03 0 thrpt 12 282.034 ± 12.122 ops/us MyBenchmark.test03 3062447746611937280 thrpt 12 253.645 ± 17.289 ops/us MyBenchmark.test03 3074515986238406656 thrpt 12 252.782 ± 15.609 ops/us MyBenchmark.test03 3074457344191496192 thrpt 12 243.416 ± 18.441 ops/us MyBenchmark.test04 0 thrpt 12 165.815 ± 4.197 ops/us MyBenchmark.test04 3062447746611937280 thrpt 12 163.729 ± 5.918 ops/us MyBenchmark.test04 3074515986238406656 thrpt 12 164.267 ± 7.493 ops/us MyBenchmark.test04 3074457344191496192 thrpt 12 164.083 ± 9.870 ops/us MyBenchmark.test05 0 thrpt 12 297.639 ± 13.674 ops/us MyBenchmark.test05 3062447746611937280 thrpt 12 212.426 ± 9.613 ops/us MyBenchmark.test05 3074515986238406656 thrpt 12 212.237 ± 11.419 ops/us MyBenchmark.test05 3074457344191496192 thrpt 12 225.235 ± 5.499 ops/us MyBenchmark.testBase 0 thrpt 12 327.570 ± 14.005 ops/us MyBenchmark.testBase 3062447746611937280 thrpt 12 340.888 ± 26.225 ops/us MyBenchmark.testBase 3074515986238406656 thrpt 12 347.679 ± 13.391 ops/us MyBenchmark.testBase 3074457344191496192 thrpt 12 334.544 ± 18.950 ops/us javaclientjartarget/benchmarks.jari6wi6f2tuusw1r1Benchmark(arg)ModeCntScoreErrorUnitsMyBenchmark.test00_org0thrpt12279.741±29.887ops/usMyBenchmark.test00_org3062447746611937280thrpt12205.673±7.439ops/usMyBenchmark.test00_org3074515986238406656thrpt12201.798±6.953ops/usMyBenchmark.test00_org3074457344191496192thrpt12190.171±39.043ops/usMyBenchmark.test010thrpt12202.220±73.463ops/usMyBenchmark.test013062447746611937280thrpt12236.309±8.704ops/usMyBenchmark.test013074515986238406656thrpt12237.174±23.063ops/usMyBenchmark.test013074457344191496192thrpt12242.547±13.411ops/usMyBenchmark.test020thrpt12299.377±10.452ops/usMyBenchmark.test023062447746611937280thrpt12206.543±8.674ops/usMyBenchmark.test023074515986238406656thrpt12210.015±14.216ops/usMyBenchmark.test023074457344191496192thrpt12206.154±9.162ops/usMyBenchmark.test030thrpt12282.034±12.122ops/usMyBenchmark.test033062447746611937280thrpt12253.645±17.289ops/usMyBenchmark.test033074515986238406656thrpt12252.782±15.609ops/usMyBenchmark.test033074457344191496192thrpt12243.416±18.441ops/usMyBenchmark.test040thrpt12165.815±4.197ops/usMyBenchmark.test043062447746611937280thrpt12163.729±5.918ops/usMyBenchmark.test043074515986238406656thrpt12164.267±7.493ops/usMyBenchmark.test043074457344191496192thrpt12164.083±9.870ops/usMyBenchmark.test050thrpt12297.639±13.674ops/usMyBenchmark.test053062447746611937280thrpt12212.426±9.613ops/usMyBenchmark.test053074515986238406656thrpt12212.237±11.419ops/usMyBenchmark.test053074457344191496192thrpt12225.235±5.499ops/usMyBenchmark.testBase0thrpt12327.570±14.005ops/usMyBenchmark.testBase3062447746611937280thrpt12340.888±26.225ops/usMyBenchmark.testBase3074515986238406656thrpt12347.679±13.391ops/usMyBenchmark.testBase3074457344191496192thrpt12334.544±18.950ops/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 265.709 ± 22.849 ops/us MyBenchmark.test00_org 3062447746611937280 thrpt 12 186.543 ± 12.618 ops/us MyBenchmark.test00_org 3074515986238406656 thrpt 12 190.523 ± 15.184 ops/us MyBenchmark.test00_org 3074457344191496192 thrpt 12 201.293 ± 20.579 ops/us MyBenchmark.test01 0 thrpt 12 250.504 ± 8.280 ops/us MyBenchmark.test01 3062447746611937280 thrpt 12 231.201 ± 15.193 ops/us MyBenchmark.test01 3074515986238406656 thrpt 12 239.506 ± 14.177 ops/us MyBenchmark.test01 3074457344191496192 thrpt 12 254.358 ± 13.892 ops/us MyBenchmark.test02 0 thrpt 12 312.997 ± 9.409 ops/us MyBenchmark.test02 3062447746611937280 thrpt 12 215.650 ± 5.710 ops/us MyBenchmark.test02 3074515986238406656 thrpt 12 211.803 ± 7.658 ops/us MyBenchmark.test02 3074457344191496192 thrpt 12 204.981 ± 8.701 ops/us MyBenchmark.test03 0 thrpt 12 279.536 ± 21.155 ops/us MyBenchmark.test03 3062447746611937280 thrpt 12 239.610 ± 16.937 ops/us MyBenchmark.test03 3074515986238406656 thrpt 12 244.587 ± 7.727 ops/us MyBenchmark.test03 3074457344191496192 thrpt 12 247.334 ± 10.070 ops/us MyBenchmark.test04 0 thrpt 12 163.851 ± 10.121 ops/us MyBenchmark.test04 3062447746611937280 thrpt 12 165.142 ± 4.311 ops/us MyBenchmark.test04 3074515986238406656 thrpt 12 165.667 ± 4.084 ops/us MyBenchmark.test04 3074457344191496192 thrpt 12 165.151 ± 7.339 ops/us MyBenchmark.test05 0 thrpt 12 316.901 ± 6.469 ops/us MyBenchmark.test05 3062447746611937280 thrpt 12 222.631 ± 7.866 ops/us MyBenchmark.test05 3074515986238406656 thrpt 12 208.247 ± 25.603 ops/us MyBenchmark.test05 3074457344191496192 thrpt 12 219.299 ± 11.461 ops/us MyBenchmark.testBase 0 thrpt 12 327.430 ± 19.111 ops/us MyBenchmark.testBase 3062447746611937280 thrpt 12 322.775 ± 18.716 ops/us MyBenchmark.testBase 3074515986238406656 thrpt 12 330.846 ± 12.044 ops/us MyBenchmark.testBase 3074457344191496192 thrpt 12 330.246 ± 13.339 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", "3062447746611937280", "3074515986238406656", "3074457344191496192"}) public long arg; @Benchmark public long testBase() { return (int)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(long i) { // HD, Figure 5-14 int x, y; if (i == 0) return 64; int n = 63; y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32); y = x <<16; if (y != 0) { n = n -16; x = y; } y = x << 8; if (y != 0) { n = n - 8; x = y; } y = x << 4; if (y != 0) { n = n - 4; x = y; } y = x << 2; if (y != 0) { n = n - 2; x = y; } return n - ((x << 1) >>> 31); } static int numberOfTrailingZeros_01(long i) { i &= -i; // lowest one bit if (i <= 0) return i == 0 ? 64 : 63; int n = -1; if (i >= 1L << 32) { n += 32; i >>>= 32; } if (i >= 1L << 16) { n += 16; i >>>= 16; } if (i >= 1L << 8) { n += 8; i >>>= 8; } if (i >= 1L << 4) { n += 4; i >>>= 4; } if (i >= 1L << 2) { n += 2; i >>>= 2; } return n + (int)i; } static int numberOfTrailingZeros_02(long i) { if (i == 0) return 64; return 63 - numberOfLeadingZeros(i & -i); } static int numberOfTrailingZeros_03(long i) { int x = (int)i; return x == 0 ? 32 + Integer_numberOfTrailingZeros((int)(i >>> 32)) : Integer_numberOfTrailingZeros(x); } static int numberOfTrailingZeros_04(long i) { return bitCount(~i & (i - 1)); } static int numberOfTrailingZeros_05(long i) { if (i == 0L) return 64; int x = (int)i; if (x == 0) { x = (int)(i >>> 32); return 63 - Integer_numberOfLeadingZeros(x & -x); } else { return 31 - Integer_numberOfLeadingZeros(x & -x); } } static int Integer_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 Integer_numberOfTrailingZeros(int i) { if (i == 0) return 32; return 31 - Integer_numberOfLeadingZeros(i & -i); } static int numberOfLeadingZeros(long i) { int x = (int)(i >>> 32); return x == 0 ? 32 + Integer_numberOfLeadingZeros((int)i) : Integer_numberOfLeadingZeros(x); } static int bitCount(long i) { // HD, Figure 5-2 i = i - ((i >>> 1) & 0x5555555555555555L); i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L); i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL; i = i + (i >>> 8); i = i + (i >>> 16); i = i + (i >>> 32); return (int)i & 0x7f; } }