Skip to content

Commit

Permalink
PARQUET-2375: Extend vectorized bit unpacking benchmark with differen…
Browse files Browse the repository at this point in the history
…t bit-widths (#1186)
  • Loading branch information
jatin-bhateja authored Nov 17, 2023
1 parent 18eedab commit 45e14a5
Showing 1 changed file with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Param;

import java.util.concurrent.TimeUnit;

Expand All @@ -38,48 +40,60 @@
*/

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 1, batchSize = 100000)
@Measurement(iterations = 1, batchSize = 100000)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@OutputTimeUnit(TimeUnit.SECONDS)
@Fork(jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
public class ByteBitPackingVectorBenchmarks {

/**
* The range of bitWidth is 1 ~ 32, change it directly if test other bitWidth.
*/
private static final int bitWidth = 7;
private static final int outputValues = 1024;
private final byte[] input = new byte[outputValues * bitWidth / 8];
private final int[] output = new int[outputValues];
private final int[] outputVector = new int[outputValues];
@Param({"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" })
private int bitWidth;
private int outputValues = 2048;

private byte[] input;
private int[] output;
private int[] outputVector;
private int totalBytesCount;
private int outCountPerVector;
private int totalByteCountVector;
private int inputByteCountPerVector;

private BytePacker bytePacker;
private BytePacker bytePackerVector;

@Setup(Level.Trial)
public void getInputBytes() {
input = new byte[outputValues * bitWidth / 8];
output = new int[outputValues];
outputVector = new int[outputValues];
totalBytesCount = input.length;

bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
bytePackerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);

outCountPerVector = bytePackerVector.getUnpackCount();
inputByteCountPerVector = outCountPerVector / 8 * bitWidth;
totalByteCountVector = totalBytesCount - inputByteCountPerVector;

for (int i = 0; i < input.length; i++) {
input[i] = (byte) i;
}
}

@Benchmark
public void testUnpack() {
BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
for (int i = 0, j = 0; i < input.length; i += bitWidth, j += 8) {
bytePacker.unpack8Values(input, i, output, j);
}
}

@Benchmark
public void testUnpackVector() {
BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
BytePacker bytePackerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);

int byteIndex = 0;
int valueIndex = 0;
int totalBytesCount = input.length;
int outCountPerVector = bytePackerVector.getUnpackCount();
int inputByteCountPerVector = outCountPerVector / 8 * bitWidth;
int totalByteCountVector = totalBytesCount - inputByteCountPerVector;

for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += outCountPerVector) {
bytePackerVector.unpackValuesUsingVector(input, byteIndex, outputVector, valueIndex);
}
Expand Down

0 comments on commit 45e14a5

Please sign in to comment.