On Tue, 28 Feb 2023 15:59:26 GMT, Eirik Bjorsnos <d...@openjdk.org> wrote:

> This PR suggests we add a vectorized equalsIgnoreCase benchmark to the set of 
> benchmarks in `org.openjdk.bench.jdk.incubator.vector`. This benchmark serves 
> as an example of how vectorization can be useful also in the area of text 
> processing. It takes advantage of the fact that ASCII and Latin-1 were 
> designed to optimize case-twiddling operations.
> 
> The code came about during the work on #12632, where vectorization was deemed 
> out of scope.
> 
> Benchmark results:
> 
> 
> Benchmark                             (size)  Mode  Cnt     Score   Error  
> Units
> EqualsIgnoreCaseBenchmark.scalar          16  avgt   15    20.671 ± 0.718  
> ns/op
> EqualsIgnoreCaseBenchmark.scalar          32  avgt   15    46.155 ± 3.258  
> ns/op
> EqualsIgnoreCaseBenchmark.scalar          64  avgt   15    68.248 ± 1.767  
> ns/op
> EqualsIgnoreCaseBenchmark.scalar         128  avgt   15   148.948 ± 0.890  
> ns/op
> EqualsIgnoreCaseBenchmark.scalar        1024  avgt   15  1090.708 ± 7.540  
> ns/op
> EqualsIgnoreCaseBenchmark.vectorized      16  avgt   15    21.872 ± 0.232  
> ns/op
> EqualsIgnoreCaseBenchmark.vectorized      32  avgt   15    11.378 ± 0.097  
> ns/op
> EqualsIgnoreCaseBenchmark.vectorized      64  avgt   15    13.703 ± 0.135  
> ns/op
> EqualsIgnoreCaseBenchmark.vectorized     128  avgt   15    21.632 ± 0.735  
> ns/op
> EqualsIgnoreCaseBenchmark.vectorized    1024  avgt   15   105.509 ± 7.493  
> ns/op

Thanks a lot for this micro benchmark.

test/micro/org/openjdk/bench/jdk/incubator/vector/EqualsIgnoreCaseBenchmark.java
 line 85:

> 83: 
> 84:             // ASCII and Latin-1 were designed to optimize case-twiddling 
> operations
> 85:             ByteVector lowerA = va.or((byte) 0x20);

Just curious, here you use lower whereas in scalar code upper is being used. 
Any reasons?

test/micro/org/openjdk/bench/jdk/incubator/vector/EqualsIgnoreCaseBenchmark.java
 line 88:

> 86: 
> 87:             // Determine which bytes represent ASCII or Latin-1 letters:
> 88:             VectorMask<Byte> asciiLetter = lowerA.lt((byte) 
> '{').and(lowerA.lt((byte) 0x60).not());

We do have GT/GE/NE etc comparison operators supported in Vector API, which you 
can use here and other places in this benchmark. e.g.
You could do lowerA.compare(GE, (byte)0x60) instead of using lt() followed 
not(). BTW did you mean to use GT here?

You will need to do the following import:
import static  jdk.incubator.vector.VectorOperators.*;

-------------

PR: https://git.openjdk.org/jdk/pull/12790

Reply via email to