More general handling of parameters for VariantContextBenchmark

This commit is contained in:
Mark DePristo 2011-11-11 10:22:19 -05:00
parent ef9f8b5d46
commit 4938569b3a
1 changed files with 30 additions and 13 deletions

View File

@ -46,13 +46,24 @@ public class VariantContextBenchmark extends SimpleBenchmark {
@Param({"100"}) @Param({"100"})
int nSamplesToTake; // set automatically by framework int nSamplesToTake; // set automatically by framework
@Param({"READ", "READ_SUBSET"})
Operation operation; // set automatically by framework
@Param({"OF_GENOTYPES", "OF_SAMPLES"})
SubContextOp subContextOp; // set automatically by framework
private String INPUT_STRING; private String INPUT_STRING;
private enum Operation { public enum Operation {
READ, READ,
READ_SUBSET READ_SUBSET
} }
public enum SubContextOp {
OF_GENOTYPES,
OF_SAMPLES
}
@Override protected void setUp() { @Override protected void setUp() {
// read it into a String so that we don't try to benchmark IO issues // read it into a String so that we don't try to benchmark IO issues
try { try {
@ -73,7 +84,7 @@ public class VariantContextBenchmark extends SimpleBenchmark {
} }
} }
private void parseGenotypes(VCFCodec codec, Operation op) { private void parseGenotypes(VCFCodec codec, Operation op, SubContextOp subop ) {
try { try {
InputStream is = new ByteArrayInputStream(INPUT_STRING.getBytes()); InputStream is = new ByteArrayInputStream(INPUT_STRING.getBytes());
AsciiLineReader lineReader = new AsciiLineReader(is); AsciiLineReader lineReader = new AsciiLineReader(is);
@ -92,30 +103,36 @@ public class VariantContextBenchmark extends SimpleBenchmark {
} }
if ( op == Operation.READ_SUBSET) if ( op == Operation.READ_SUBSET)
processOneVC(vc, samples); processOneVC(vc, samples, subop);
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Benchmarking run failure because of " + e.getMessage()); System.out.println("Benchmarking run failure because of " + e.getMessage());
} }
} }
public void timeOriginalRead(int rep) { public void timeMe(int rep) {
for ( int i = 0; i < rep; i++ ) for ( int i = 0; i < rep; i++ )
parseGenotypes(new VCFCodec(), Operation.READ); parseGenotypes(new VCFCodec(), operation, subContextOp);
}
public void timeOriginalReadSubset(int rep) {
for ( int i = 0; i < rep; i++ )
parseGenotypes(new VCFCodec(), Operation.READ_SUBSET);
} }
public static void main(String[] args) { public static void main(String[] args) {
CaliperMain.main(VariantContextBenchmark.class, args); CaliperMain.main(VariantContextBenchmark.class, args);
} }
private static final void processOneVC(VariantContext vc, List<String> samples) { private static final void processOneVC(VariantContext vc, List<String> samples, SubContextOp subop) {
VariantContext sub = vc.subContextFromGenotypes(vc.getGenotypes(samples).values(), vc.getAlleles()); VariantContext sub;
switch ( subop ) {
case OF_GENOTYPES:
sub = vc.subContextFromGenotypes(vc.getGenotypes(samples).values(), vc.getAlleles());
break;
case OF_SAMPLES:
sub = vc.subContextFromSamples(samples, vc.getAlleles());
break;
default:
throw new RuntimeException("Unexpected op: " + subop);
}
sub.getNSamples(); sub.getNSamples();
} }
} }