forked from jasder/antlr
Merge pull request #1580 from sharwell/portable-hash
Use MurmurHash in TestPerformance so results are comparable across targets
This commit is contained in:
commit
c7a9fe364a
|
@ -76,8 +76,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
import org.antlr.v4.runtime.misc.MurmurHash;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
@ -825,7 +824,7 @@ public class TestPerformance extends BaseJavaToolTest {
|
|||
results.add(futureChecksum);
|
||||
}
|
||||
|
||||
Checksum checksum = new CRC32();
|
||||
MurmurHashChecksum checksum = new MurmurHashChecksum();
|
||||
int currentIndex = -1;
|
||||
for (Future<FileParseResult> future : results) {
|
||||
currentIndex++;
|
||||
|
@ -1115,14 +1114,11 @@ public class TestPerformance extends BaseJavaToolTest {
|
|||
assertTrue(success);
|
||||
}
|
||||
|
||||
private static void updateChecksum(Checksum checksum, int value) {
|
||||
checksum.update((value) & 0xFF);
|
||||
checksum.update((value >>> 8) & 0xFF);
|
||||
checksum.update((value >>> 16) & 0xFF);
|
||||
checksum.update((value >>> 24) & 0xFF);
|
||||
private static void updateChecksum(MurmurHashChecksum checksum, int value) {
|
||||
checksum.update(value);
|
||||
}
|
||||
|
||||
private static void updateChecksum(Checksum checksum, Token token) {
|
||||
private static void updateChecksum(MurmurHashChecksum checksum, Token token) {
|
||||
if (token == null) {
|
||||
checksum.update(0);
|
||||
return;
|
||||
|
@ -1154,7 +1150,7 @@ public class TestPerformance extends BaseJavaToolTest {
|
|||
|
||||
@Override
|
||||
public FileParseResult parseFile(CharStream input, int currentPass, int thread) {
|
||||
final Checksum checksum = new CRC32();
|
||||
final MurmurHashChecksum checksum = new MurmurHashChecksum();
|
||||
|
||||
final long startTime = System.nanoTime();
|
||||
assert thread >= 0 && thread < NUMBER_OF_THREADS;
|
||||
|
@ -1835,9 +1831,9 @@ public class TestPerformance extends BaseJavaToolTest {
|
|||
private static final int ENTER_RULE = 3;
|
||||
private static final int EXIT_RULE = 4;
|
||||
|
||||
private final Checksum checksum;
|
||||
private final MurmurHashChecksum checksum;
|
||||
|
||||
public ChecksumParseTreeListener(Checksum checksum) {
|
||||
public ChecksumParseTreeListener(MurmurHashChecksum checksum) {
|
||||
this.checksum = checksum;
|
||||
}
|
||||
|
||||
|
@ -1928,6 +1924,24 @@ public class TestPerformance extends BaseJavaToolTest {
|
|||
}
|
||||
}
|
||||
|
||||
private static class MurmurHashChecksum {
|
||||
private int value;
|
||||
private int count;
|
||||
|
||||
public MurmurHashChecksum() {
|
||||
this.value = MurmurHash.initialize();
|
||||
}
|
||||
|
||||
public void update(int value) {
|
||||
this.value = MurmurHash.update(this.value, value);
|
||||
this.count++;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return MurmurHash.finish(value, count);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 20000)
|
||||
public void testExponentialInclude() {
|
||||
String grammarFormat =
|
||||
|
|
Loading…
Reference in New Issue