bsglz commented on PR #5171:
URL: https://github.com/apache/hbase/pull/5171#issuecomment-1518476388

   Test code:
   
   ```
   /*
    * 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.yihong;
   
   import org.apache.hadoop.hbase.*;
   import org.apache.hadoop.hbase.util.Bytes;
   import org.apache.hadoop.hbase.util.Pair;
   import org.openjdk.jmh.annotations.*;
   import org.openjdk.jmh.runner.Runner;
   import org.openjdk.jmh.runner.RunnerException;
   import org.openjdk.jmh.runner.options.Options;
   import org.openjdk.jmh.runner.options.OptionsBuilder;
   
   import java.nio.ByteBuffer;
   import java.util.concurrent.TimeUnit;
   
   @Fork(1)
   @State(Scope.Thread)
   @BenchmarkMode(Mode.Throughput)
   @OutputTimeUnit(TimeUnit.SECONDS)
   public class BenchmarkForNormal {
   
       @Param({"fam", "fam1"})
       String p1;
   
       @Param({"fam", "fam1"})
       String p2;
   
       byte[] row1 = Bytes.toBytes("row1");
       byte[] qual1 = Bytes.toBytes("qual1");
       byte[] val = Bytes.toBytes("val");
       KeyValue kv1;
       KeyValue kv2;
       Cell bbCell1;
       Cell bbCell2;
   
       @Setup
       public void initParams() {
           byte[] fam0 = Bytes.toBytes(p1);
           byte[] fam1 = Bytes.toBytes(p2);
           Pair<byte[], byte[]> famPair = new Pair(fam0, fam1);
           kv1 = new KeyValue(row1, famPair.getFirst(), qual1, val);
           kv2 = new KeyValue(row1, famPair.getSecond(), qual1, val);
           ByteBuffer buffer = ByteBuffer.wrap(kv1.getBuffer());
           bbCell1 = new ByteBufferKeyValue(buffer, 0, buffer.remaining());
           buffer = ByteBuffer.wrap(kv2.getBuffer());
           bbCell2 = new ByteBufferKeyValue(buffer, 0, buffer.remaining());
       }
   
       @Benchmark
       public void old_compareKV() {
           CellComparatorOld.OLD_COMPARATOR.compare(kv1, kv2);
       }
   
       @Benchmark
       public void new_compareKV() {
           CellComparatorImpl.COMPARATOR.compare(kv1, kv2);
       }
   
       @Benchmark
       public void old_compareBBKV() {
           CellComparatorOld.OLD_COMPARATOR.compare(bbCell1, bbCell2);
       }
   
       @Benchmark
       public void new_compareBBKV() {
           CellComparatorImpl.COMPARATOR.compare(bbCell1, bbCell2);
       }
   
       @Benchmark
       public void old_compareKVVsBBKV() {
           CellComparatorOld.OLD_COMPARATOR.compare(kv1, bbCell2);
       }
   
       @Benchmark
       public void new_compareKVVsBBKV() {
           CellComparatorImpl.COMPARATOR.compare(kv1, bbCell2);
       }
   
       public static void main(String[] args) throws RunnerException {
           Options opt = new OptionsBuilder()
                   .include(BenchmarkForNormal.class.getSimpleName())
                   .build();
           new Runner(opt).run();
       }
   }
   
   /*
    * 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.yihong;
   
   import org.apache.hadoop.hbase.*;
   import org.apache.hadoop.hbase.util.Bytes;
   import org.apache.hadoop.hbase.util.Pair;
   import org.openjdk.jmh.annotations.*;
   import org.openjdk.jmh.runner.Runner;
   import org.openjdk.jmh.runner.RunnerException;
   import org.openjdk.jmh.runner.options.Options;
   import org.openjdk.jmh.runner.options.OptionsBuilder;
   
   import java.nio.ByteBuffer;
   import java.util.concurrent.TimeUnit;
   
   @Fork(1)
   @State(Scope.Thread)
   @BenchmarkMode(Mode.Throughput)
   @OutputTimeUnit(TimeUnit.SECONDS)
   public class BenchmarkForInnerStore {
   
       @Param({"", "fam1"})
       String p1;
   
       @Param({"", "fam1"})
       String p2;
   
       byte[] row1 = Bytes.toBytes("row1");
       byte[] qual1 = Bytes.toBytes("qual1");
       byte[] val = Bytes.toBytes("val");
       KeyValue kv1;
       KeyValue kv2;
       Cell bbCell1;
       Cell bbCell2;
   
       @Setup
       public void initParams() {
           byte[] fam0 = Bytes.toBytes(p1);
           byte[] fam1 = Bytes.toBytes(p2);
           Pair<byte[], byte[]> famPair = new Pair(fam0, fam1);
           kv1 = new KeyValue(row1, famPair.getFirst(), qual1, val);
           kv2 = new KeyValue(row1, famPair.getSecond(), qual1, val);
           ByteBuffer buffer = ByteBuffer.wrap(kv1.getBuffer());
           bbCell1 = new ByteBufferKeyValue(buffer, 0, buffer.remaining());
           buffer = ByteBuffer.wrap(kv2.getBuffer());
           bbCell2 = new ByteBufferKeyValue(buffer, 0, buffer.remaining());
       }
   
       @Benchmark
       public void old_compareKV() {
           CellComparatorOld.OLD_COMPARATOR.compare(kv1, kv2);
       }
   
       @Benchmark
       public void new_compareKV() {
           InnerStoreCellComparator.INNER_STORE_COMPARATOR.compare(kv1, kv2);
       }
   
       @Benchmark
       public void old_compareBBKV() {
           CellComparatorOld.OLD_COMPARATOR.compare(bbCell1, bbCell2);
       }
   
       @Benchmark
       public void new_compareBBKV() {
           InnerStoreCellComparator.INNER_STORE_COMPARATOR.compare(bbCell1, 
bbCell2);
       }
   
       @Benchmark
       public void old_compareKVVsBBKV() {
           CellComparatorOld.OLD_COMPARATOR.compare(kv1, bbCell2);
       }
   
       @Benchmark
       public void new_compareKVVsBBKV() {
           InnerStoreCellComparator.INNER_STORE_COMPARATOR.compare(kv1, 
bbCell2);
       }
   
       public static void main(String[] args) throws RunnerException {
           Options opt = new OptionsBuilder()
                   .include(BenchmarkForInnerStore.class.getSimpleName())
                   .build();
           new Runner(opt).run();
       }
   }
   //pom.xml
           <dependency>
               <groupId>org.apache.hbase</groupId>
               <artifactId>hbase-common</artifactId>
               <version>3.0.0-alpha-4-SNAPSHOT</version>
           </dependency>
           <dependency>
               <groupId>org.apache.hbase</groupId>
               <artifactId>hbase-server</artifactId>
               <version>3.0.0-alpha-4-SNAPSHOT</version>
           </dependency>
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to