Skip to content

Commit ae84455

Browse files
committed
JMH benchmark for buffered checksum
1 parent f1f73ef commit ae84455

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.lucene.benchmark.jmh;
18+
19+
import java.util.concurrent.TimeUnit;
20+
import java.util.zip.CRC32;
21+
import java.util.zip.CRC32C;
22+
import org.apache.lucene.store.BufferedChecksum;
23+
import org.openjdk.jmh.annotations.*;
24+
25+
@BenchmarkMode(Mode.Throughput)
26+
@OutputTimeUnit(TimeUnit.SECONDS)
27+
@State(Scope.Benchmark)
28+
@Warmup(iterations = 5, time = 5)
29+
@Measurement(iterations = 5, time = 5)
30+
@Fork(1)
31+
public class BufferedChecksumBenchmark {
32+
33+
@Param({"1024", "8192", "65536"})
34+
private int dataSize;
35+
36+
@Param({"1024", "2048", "4096"})
37+
private int bufferSize;
38+
39+
private byte[] data;
40+
41+
@Setup
42+
public void setup() {
43+
data = new byte[dataSize];
44+
for (int i = 0; i < dataSize; i++) {
45+
data[i] = (byte) i;
46+
}
47+
}
48+
49+
@Benchmark
50+
public long bufferedCRC32SmallUpdates() {
51+
BufferedChecksum checksum = new BufferedChecksum(new CRC32(), bufferSize);
52+
for (int i = 0; i < data.length; i++) {
53+
checksum.update(data[i]); // Single byte updates
54+
}
55+
return checksum.getValue();
56+
}
57+
58+
@Benchmark
59+
public long bufferedCRC32BulkUpdate() {
60+
BufferedChecksum checksum = new BufferedChecksum(new CRC32(), bufferSize);
61+
checksum.update(data, 0, data.length);
62+
return checksum.getValue();
63+
}
64+
65+
// CRC32C benchmarks
66+
@Benchmark
67+
public long bufferedCRC32CSmallUpdates() {
68+
BufferedChecksum checksum = new BufferedChecksum(new CRC32C(), bufferSize);
69+
for (int i = 0; i < data.length; i++) {
70+
checksum.update(data[i]);
71+
}
72+
return checksum.getValue();
73+
}
74+
75+
@Benchmark
76+
public long bufferedCRC32CBulkUpdate() {
77+
BufferedChecksum checksum = new BufferedChecksum(new CRC32C(), bufferSize);
78+
checksum.update(data, 0, data.length);
79+
return checksum.getValue();
80+
}
81+
}

0 commit comments

Comments
 (0)