asdf2014 commented on issue #5980: Various changes about a few coding 
specifications
URL: https://github.com/apache/incubator-druid/pull/5980#issuecomment-405439513
 
 
   @leventov PTAL.
   
   1. Set the level of `ToArrayCallWithZeroLengthArrayArgument` inspection as 
`warning`, because use `Collections.singletonList` will cause a 
ClassCastException in 
`io.druid.server.coordinator.CostBalancerStrategyBenchmark#factoryClasses` and 
`io.druid.collections.bitmap.WrappedRoaringBitmapTest#factoryClasses`.
   
   2. Also set the level of `ToArrayCallWithZeroLengthArrayArgument` coding 
inspection as `warning` and add `BY_LEVEL` option, because 
[teamcity](https://teamcity.jetbrains.com/viewLog.html?buildId=1526603&tab=Inspection&buildTypeId=OpenSourceProjects_Druid_InspectionsPullRequests)
 is misunderstanding this inspection, teamcity think `pre-size` way is better, 
but it is not.
   
   ```java
   @State(Scope.Thread)
   @OutputTimeUnit(TimeUnit.NANOSECONDS)
   @BenchmarkMode(Mode.AverageTime)
   public class ToArrayBenchmark {
   
       @Param({"1", "100", "1000", "5000", "10000", "100000"})
       private int n;
   
       private final List<Object> list = new ArrayList<>();
   
       @Setup
       public void populateList() {
           for (int i = 0; i < n; i++) {
               list.add(0);
           }
       }
   
       @Benchmark
       public Object[] preSize() {
           return list.toArray(new Object[n]);
       }
   
       @Benchmark
       public Object[] resize() {
           return list.toArray(new Object[0]);
       }
   
       /*
       Integer List:
       Benchmark                    (n)  Mode  Cnt       Score        Error  
Units
       ToArrayBenchmark.preSize       1  avgt    3      41.552 ±    108.030  
ns/op
       ToArrayBenchmark.preSize     100  avgt    3     216.449 ±    799.501  
ns/op
       ToArrayBenchmark.preSize    1000  avgt    3    2087.965 ±   6027.778  
ns/op
       ToArrayBenchmark.preSize    5000  avgt    3    9098.358 ±  14603.493  
ns/op
       ToArrayBenchmark.preSize   10000  avgt    3   24204.199 ± 121468.232  
ns/op
       ToArrayBenchmark.preSize  100000  avgt    3  188183.618 ± 369455.090  
ns/op
       ToArrayBenchmark.resize        1  avgt    3      18.987 ±     36.449  
ns/op
       ToArrayBenchmark.resize      100  avgt    3     265.549 ±   1125.008  
ns/op
       ToArrayBenchmark.resize     1000  avgt    3    1560.713 ±   2922.186  
ns/op
       ToArrayBenchmark.resize     5000  avgt    3    7804.810 ±   8333.390  
ns/op
       ToArrayBenchmark.resize    10000  avgt    3   24791.026 ±  78459.936  
ns/op
       ToArrayBenchmark.resize   100000  avgt    3  158891.642 ±  56055.895  
ns/op
       Object List:
       Benchmark                    (n)  Mode  Cnt      Score       Error  Units
       ToArrayBenchmark.preSize       1  avgt    3     36.306 ±    96.612  ns/op
       ToArrayBenchmark.preSize     100  avgt    3     52.372 ±    84.159  ns/op
       ToArrayBenchmark.preSize    1000  avgt    3    449.807 ±   215.692  ns/op
       ToArrayBenchmark.preSize    5000  avgt    3   2080.172 ±  2003.726  ns/op
       ToArrayBenchmark.preSize   10000  avgt    3   4657.937 ±  8432.624  ns/op
       ToArrayBenchmark.preSize  100000  avgt    3  51980.829 ± 46920.314  ns/op
       ToArrayBenchmark.resize        1  avgt    3     16.747 ±    85.131  ns/op
       ToArrayBenchmark.resize      100  avgt    3     43.803 ±    28.704  ns/op
       ToArrayBenchmark.resize     1000  avgt    3    404.681 ±   132.986  ns/op
       ToArrayBenchmark.resize     5000  avgt    3   1972.649 ±   174.691  ns/op
       ToArrayBenchmark.resize    10000  avgt    3   4021.440 ±  1114.212  ns/op
       ToArrayBenchmark.resize   100000  avgt    3  44204.167 ± 76714.850  ns/op
        */
       public static void main(String[] args) throws Exception {
           Options opt = new OptionsBuilder()
                   .include(ToArrayBenchmark.class.getSimpleName())
                   .forks(1)
                   .warmupIterations(1)
                   .measurementIterations(3)
                   .threads(1)
                   .build();
           new Runner(opt).run();
       }
   }
   ```
   Tips: Full code is 
[here](https://github.com/asdf2014/yuzhouwan/blob/master/yuzhouwan-hacker/src/main/java/com/yuzhouwan/hacker/algorithms/collection/ToArrayBenchmark.java).
   
   3. Added `[a-z][a-zA-Z0-9_]*\.equals\((\"|[A-Z_]+\))` into checkstyle config 
file.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@druid.apache.org
For additional commands, e-mail: dev-h...@druid.apache.org

Reply via email to