Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto;
 
 
 import java.util.List;
 
 import static com.facebook.presto.spi.block.SortOrder.ASC_NULLS_FIRST;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.BooleanType.BOOLEAN;
 import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static java.util.Collections.nCopies;
 
 @Fork(3)
 @Warmup(iterations = 10, time = 500, timeUnit = .)
 @Measurement(iterations = 10, time = 500, timeUnit = .)
 {
     @Benchmark
     public int runBenchmark(BenchmarkData data)
     {
         PageSorter pageSorter = new PagesIndexPageSorter();
         long[] addresses = pageSorter.sort(data.typesdata.pagesdata.sortChannelsnCopies(data.sortChannels.size(), ), 10_000);
         return addresses.length;
     }
 
     private static List<PagecreatePages(int pageCountint channelCountType type)
     {
         int positionCount = . / (channelCount * 8);
 
         List<Pagepages = new ArrayList<>(pageCount);
         for (int numPage = 0; numPage < pageCountnumPage++) {
             Block[] blocks = new Block[channelCount];
             for (int numChannel = 0; numChannel < channelCountnumChannel++) {
                 if (type.equals()) {
                     blocks[numChannel] = BlockAssertions.createLongSequenceBlock(0, positionCount);
                 }
                 else if (type.equals()) {
                     blocks[numChannel] = BlockAssertions.createStringSequenceBlock(0, positionCount);
                 }
                 else if (type.equals()) {
                     blocks[numChannel] = BlockAssertions.createDoubleSequenceBlock(0, positionCount);
                 }
                 else if (type.equals()) {
                     blocks[numChannel] = BlockAssertions.createBooleanSequenceBlock(0, positionCount);
                 }
                 else {
                     throw new IllegalArgumentException("Unsupported type: " + type);
                 }
             }
             pages.add(new Page(blocks));
         }
         return pages;
     }
 
     @State(.)
     public static class BenchmarkData
     {
         @Param({ "2""3""4""5" })
         private int numSortChannels;
 
         @Param({ "BIGINT""VARCHAR""DOUBLE""BOOLEAN" })
         private String sortChannelType;
        private List<Pagepages;
        private final int maxPages = 500;
        public List<Typetypes;
        public List<IntegersortChannels;
        @Setup
        public void setup()
        {
            int totalChannels = 20;
            Type type = getType();
             = createPages(totalChannelstype);
             = nCopies(totalChannelstype);
             = new ArrayList<>();
            for (int i = 0; i < i++) {
                .add(i);
            }
        }
        private Type getType()
        {
            switch () {
                case "BIGINT":
                    return ;
                case "VARCHAR":
                    return ;
                case "DOUBLE":
                    return ;
                case "BOOLEAN":
                    return ;
            }
            throw new IllegalArgumentException("Unsupported type: " + );
        }
    }
    public static void main(String[] args)
            throws RunnerException
    {
        Options options = new OptionsBuilder()
                .verbosity(.)
                .include(".*" + BenchmarkPagesIndexPageSorter.class.getSimpleName() + ".*")
                .build();
        new Runner(options).run();
    }
New to GrepCode? Check out our FAQ X