gf2121 commented on issue #12639:
URL: https://github.com/apache/lucene/issues/12639#issuecomment-1752926917

   > is it the number of longs or the number of bits?
   
   It is the number of longs. Here is the whole class:
   ```
   @BenchmarkMode(Mode.Throughput)
   @OutputTimeUnit(TimeUnit.MICROSECONDS)
   @State(Scope.Benchmark)
   @Warmup(iterations = 3, time = 3)
   @Measurement(iterations = 5, time = 3)
   @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
   public class BitcountBenchmark {
   
     static final VectorSpecies<Long> PREFERRED_LONG_SPECIES
         = LongVector.SPECIES_MAX.withShape(
             VectorShape.forBitSize(IntVector.SPECIES_PREFERRED.vectorBitSize() 
<< 1));
   
     private long[] longs;
   
     @Param({"1024"})
     int size;
   
     @Setup(Level.Trial)
     public void init() {
       longs = new long[size];
       for (int i = 0; i < size; i++) {
         longs[i] = ThreadLocalRandom.current().nextLong();
       }
       if (bitCountOld() != bitCountNew()) {
         throw new RuntimeException("New is wrong");
       }
       if (bitCountOld() != bitCountNewInt()) {
         throw new RuntimeException("New is wrong");
       }
     }
   
     @Benchmark
     public int bitCountOld() {
       int sum = 0;
       for (int i = 0; i < size; i++) {
         sum += Long.bitCount(longs[i]);
       }
       return sum;
     }
   
     @Benchmark
     public int bitCountNew() {
       int i = 0;
       int res = 0;
       int upperBound = PREFERRED_LONG_SPECIES.loopBound(longs.length);
       LongVector acc = LongVector.zero(PREFERRED_LONG_SPECIES);
       for (; i < upperBound; i += PREFERRED_LONG_SPECIES.length()) {
         LongVector longVector = LongVector.fromArray(PREFERRED_LONG_SPECIES, 
longs, i);
         LongVector bitCount = longVector.lanewise(VectorOperators.BIT_COUNT);
         acc = acc.add(bitCount);
       }
       res += (int) acc.reduceLanes(VectorOperators.ADD);
       for (; i < longs.length; i++) {
         res += Long.bitCount(longs[i]);
       }
       return res;
     }
   }
   ```


-- 
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...@lucene.apache.org

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


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

Reply via email to