neoremind edited a comment on issue #1895: [CALCITE-3891] Remove use of 
Pair.zip in RelTraitSet#satisfies
URL: https://github.com/apache/calcite/pull/1895#issuecomment-607639682
 
 
   I benchmark on the two ways to iterate. The result shows for small size, the 
optimization works well (I think we usually do not have many traits, like less 
than 4? limit to convention, collation or distribution?), as the size goes big, 
the optimization degrades, almost the same.
   
   ```
   Benchmark                 (length)  Mode  Cnt   Score    Error  Units
   PairZipTest4.testPairZip         2  avgt    3  19.314 ± 29.937  ns/op
   PairZipTest4.testSimple          2  avgt    3  11.391 ± 12.701  ns/op
   
   PairZipTest4.testPairZip         4  avgt    3  22.803 ± 28.147  ns/op
   PairZipTest4.testSimple          4  avgt    3  14.911 ±  2.887  ns/op
   
   PairZipTest4.testPairZip         8  avgt    3  28.538 ± 26.880  ns/op
   PairZipTest4.testSimple          8  avgt    3  20.914 ± 27.209  ns/op
   
   PairZipTest4.testPairZip        16  avgt    3  38.776 ± 31.445  ns/op
   PairZipTest4.testSimple         16  avgt    3  35.192 ± 17.443  ns/op
   
   PairZipTest4.testPairZip        32  avgt    3  61.833 ± 55.993  ns/op
   PairZipTest4.testSimple         32  avgt    3  62.397 ±  7.620  ns/op
   ```
   
   Benchmark source code:
   ```
   @Fork(value = 1)
   @Measurement(iterations = 3, time = 10, timeUnit = TimeUnit.SECONDS)
   @Warmup(iterations = 1, time = 10, timeUnit = TimeUnit.SECONDS)
   @BenchmarkMode(Mode.AverageTime)
   @OutputTimeUnit(TimeUnit.NANOSECONDS)
   @State(Scope.Benchmark)
   public class PairZipTest {
   
     @Param({"2", "4", "8", "16", "32"})
     int length;
   
     List<Integer> a1;
     List<Integer> a2;
   
     @Setup
     public void setUp() {
       a1 = new ArrayList<>(length);
       a2 = new ArrayList<>(length);
       for (int i = 0; i < length; i++) {
         a1.add(i);
         a2.add(i);
       }
     }
   
     @Benchmark
     public boolean testPairZip() {
       for (Pair<Integer, Integer> pair : Pair.zip(a1, a2)) {
         if (!pair.left.equals(pair.right)) {
           return false;
         }
       }
       return true;
     }
   
     @Benchmark
     public boolean testSimple() {
       for (int i = 0; i < length; i++) {
         if (!a1.get(i).equals(a2.get(i))) {
           return false;
         }
       }
       return true;
     }
   
     public static void main(String[] args) throws RunnerException {
       Options opt = new OptionsBuilder()
           .include(PairZipTest.class.getSimpleName())
           .build();
       new Runner(opt).run();
     }
   }
   ```
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to