whbing commented on PR #6974:
URL: https://github.com/apache/ozone/pull/6974#issuecomment-2294614118

   Three methods for filtering benchmark:
   ```xml
           <dependency>
               <groupId>org.openjdk.jmh</groupId>
               <artifactId>jmh-core</artifactId>
               <version>1.21</version>
           </dependency>
           <dependency>
               <groupId>org.openjdk.jmh</groupId>
               <artifactId>jmh-generator-annprocess</artifactId>
               <version>1.21</version>
               <scope>provided</scope>
           </dependency>
   ```
   ```java
   
   import org.openjdk.jmh.annotations.*;
   import java.util.*;
   import java.util.concurrent.ConcurrentHashMap;
   import java.util.concurrent.TimeUnit;
   import java.util.stream.Collectors;
   import java.util.stream.IntStream;
   
   @BenchmarkMode(Mode.AverageTime)
   @OutputTimeUnit(TimeUnit.MILLISECONDS)
   @State(Scope.Benchmark)
   public class ECDataIndexesBenchmark {
   
     private static final Map<Integer, Set<Integer>> EC_DATA_INDEXES = new 
ConcurrentHashMap<>();
     private static final int D = 6;
     private Set<Integer> replicaIndexes;
   
     @Setup
     public void setup() {
       EC_DATA_INDEXES.clear();
       // Initialize a mock collection
       replicaIndexes = IntStream.rangeClosed(1, 
9).boxed().collect(Collectors.toSet());
     }
   
     @Benchmark
     @Threads(100)
     public boolean testComputeIfAbsentAndContainsAll() {
       Set<Integer> dataIndexes = EC_DATA_INDEXES.computeIfAbsent(D, k ->
           IntStream.rangeClosed(1, k).boxed().collect(Collectors.toSet()));
       return !replicaIndexes.containsAll(dataIndexes);
     }
   
     @Benchmark
     @Threads(100)
     public boolean testDirectPutAndContainsAll() {
       Set<Integer> dataIndexes = IntStream.rangeClosed(1, 
D).boxed().collect(Collectors.toSet());
       EC_DATA_INDEXES.put(D, dataIndexes);
       return !replicaIndexes.containsAll(dataIndexes);
     }
   
     @Benchmark
     @Threads(100)
     public boolean testIndexCompare() {
       List<Integer> indexes = replicaIndexes.stream()
           .sorted()
           .collect(Collectors.toList());
       // Check if the D-th element (0-based index D-1) is equal to D
       return !(indexes.size() >= D && indexes.get(D - 1) == D);
     }
   
     public static void main(String[] args) throws Exception {
       org.openjdk.jmh.Main.main(args);
     }
   }
   
   ```
   ```java
   # JMH version: 1.21
   # VM version: JDK 1.8.0_171, Java HotSpot(TM) 64-Bit Server VM, 25.171-b11
   # VM invoker: 
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/bin/java
   # VM options: -javaagent:/Applications/IntelliJ 
IDEA.app/Contents/lib/idea_rt.jar=64676:/Applications/IntelliJ 
IDEA.app/Contents/bin -Dfile.encoding=UTF-8
   # Warmup: 2 iterations, 10 s each
   # Measurement: 2 iterations, 10 s each
   # Timeout: 10 min per iteration
   # Threads: 100 threads, will synchronize iterations
   # Benchmark mode: Average time, time/op
   # Benchmark: 
cn.whbing.hadoop.benchmark.ECDataIndexesBenchmark.testComputeIfAbsentAndContainsAll
   
   # Run progress: 0.00% complete, ETA 00:04:00
   # Fork: 1 of 2
   # Warmup Iteration   1: 0.016 ±(99.9%) 0.001 ms/op
   # Warmup Iteration   2: 0.017 ±(99.9%) 0.001 ms/op
   Iteration   1: 0.019 ±(99.9%) 0.001 ms/op
   Iteration   2: 0.018 ±(99.9%) 0.001 ms/op
   
   # Run progress: 16.67% complete, ETA 00:03:25
   # Fork: 2 of 2
   # Warmup Iteration   1: 0.017 ±(99.9%) 0.001 ms/op
   # Warmup Iteration   2: 0.018 ±(99.9%) 0.001 ms/op
   Iteration   1: 0.018 ±(99.9%) 0.001 ms/op
   Iteration   2: 0.018 ±(99.9%) 0.001 ms/op
   
   
   Result 
"cn.whbing.hadoop.benchmark.ECDataIndexesBenchmark.testComputeIfAbsentAndContainsAll":
     0.018 ±(99.9%) 0.004 ms/op [Average]
     (min, avg, max) = (0.018, 0.018, 0.019), stdev = 0.001
     CI (99.9%): [0.014, 0.022] (assumes normal distribution)
   
   
   # JMH version: 1.21
   # VM version: JDK 1.8.0_171, Java HotSpot(TM) 64-Bit Server VM, 25.171-b11
   # VM invoker: 
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/bin/java
   # VM options: -javaagent:/Applications/IntelliJ 
IDEA.app/Contents/lib/idea_rt.jar=64676:/Applications/IntelliJ 
IDEA.app/Contents/bin -Dfile.encoding=UTF-8
   # Warmup: 2 iterations, 10 s each
   # Measurement: 2 iterations, 10 s each
   # Timeout: 10 min per iteration
   # Threads: 100 threads, will synchronize iterations
   # Benchmark mode: Average time, time/op
   # Benchmark: 
cn.whbing.hadoop.benchmark.ECDataIndexesBenchmark.testDirectPutAndContainsAll
   
   # Run progress: 33.33% complete, ETA 00:02:44
   # Fork: 1 of 2
   # Warmup Iteration   1: 0.024 ±(99.9%) 0.001 ms/op
   # Warmup Iteration   2: 0.023 ±(99.9%) 0.001 ms/op
   Iteration   1: 0.023 ±(99.9%) 0.001 ms/op
   Iteration   2: 0.023 ±(99.9%) 0.001 ms/op
   
   # Run progress: 50.00% complete, ETA 00:02:03
   # Fork: 2 of 2
   # Warmup Iteration   1: 0.022 ±(99.9%) 0.001 ms/op
   # Warmup Iteration   2: 0.023 ±(99.9%) 0.001 ms/op
   Iteration   1: 0.023 ±(99.9%) 0.001 ms/op
   Iteration   2: 0.023 ±(99.9%) 0.001 ms/op
   
   
   Result 
"cn.whbing.hadoop.benchmark.ECDataIndexesBenchmark.testDirectPutAndContainsAll":
     0.023 ±(99.9%) 0.001 ms/op [Average]
     (min, avg, max) = (0.023, 0.023, 0.023), stdev = 0.001
     CI (99.9%): [0.021, 0.024] (assumes normal distribution)
   
   
   # JMH version: 1.21
   # VM version: JDK 1.8.0_171, Java HotSpot(TM) 64-Bit Server VM, 25.171-b11
   # VM invoker: 
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/bin/java
   # VM options: -javaagent:/Applications/IntelliJ 
IDEA.app/Contents/lib/idea_rt.jar=64676:/Applications/IntelliJ 
IDEA.app/Contents/bin -Dfile.encoding=UTF-8
   # Warmup: 2 iterations, 10 s each
   # Measurement: 2 iterations, 10 s each
   # Timeout: 10 min per iteration
   # Threads: 100 threads, will synchronize iterations
   # Benchmark mode: Average time, time/op
   # Benchmark: 
cn.whbing.hadoop.benchmark.ECDataIndexesBenchmark.testIndexCompare
   
   # Run progress: 66.67% complete, ETA 00:01:22
   # Fork: 1 of 2
   # Warmup Iteration   1: 0.004 ±(99.9%) 0.001 ms/op
   # Warmup Iteration   2: 0.004 ±(99.9%) 0.001 ms/op
   Iteration   1: 0.004 ±(99.9%) 0.001 ms/op
   Iteration   2: 0.004 ±(99.9%) 0.001 ms/op
   
   # Run progress: 83.33% complete, ETA 00:00:41
   # Fork: 2 of 2
   # Warmup Iteration   1: 0.004 ±(99.9%) 0.001 ms/op
   # Warmup Iteration   2: 0.004 ±(99.9%) 0.001 ms/op
   Iteration   1: 0.004 ±(99.9%) 0.001 ms/op
   Iteration   2: 0.005 ±(99.9%) 0.001 ms/op
   
   
   Result "cn.whbing.hadoop.benchmark.ECDataIndexesBenchmark.testIndexCompare":
     0.004 ±(99.9%) 0.002 ms/op [Average]
     (min, avg, max) = (0.004, 0.004, 0.005), stdev = 0.001
     CI (99.9%): [0.002, 0.006] (assumes normal distribution)
   
   
   # Run complete. Total time: 00:04:08
   
   REMEMBER: The numbers below are just data. To gain reusable insights, you 
need to follow up on
   why the numbers are the way they are. Use profilers (see -prof, -lprof), 
design factorial
   experiments, perform baseline and negative tests that provide experimental 
control, make sure
   the benchmarking environment is safe on JVM/OS/HW level, ask for reviews 
from the domain experts.
   Do not assume the numbers tell you what you want them to tell.
   
   Benchmark                                                 Mode  Cnt  Score   
Error  Units
   ECDataIndexesBenchmark.testComputeIfAbsentAndContainsAll  avgt    4  0.018 ± 
0.004  ms/op
   ECDataIndexesBenchmark.testDirectPutAndContainsAll        avgt    4  0.023 ± 
0.001  ms/op
   ECDataIndexesBenchmark.testIndexCompare                   avgt    4  0.004 ± 
0.002  ms/op
   
   Process finished with exit code 0
   
   ```
   So, `testIndexCompare`  better.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to