Skip to content

Commit a216f92

Browse files
committed
more precise comparison of parsing speed between mtf and pdb file formats
1 parent 2e3b35f commit a216f92

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfPerformance.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,41 +95,52 @@ public byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
9595

9696
@Test
9797
public void test3HBX() throws Exception{
98-
String pdbId = "3HBX";
98+
String pdbId = "3hbx";
99+
100+
pdbId = pdbId.toUpperCase();
99101

100102
URL url = new URL("https://files.rcsb.org/download/"+pdbId+".pdb.gz");
101103

102104
String pdbFile = convertStreamToString(new GZIPInputStream(url.openStream()));
103105

104-
long pdbStart = System.currentTimeMillis();
106+
long totalTimePDB = 0;
107+
long totalTimeMMTF = 0;
108+
109+
byte[] pdbBytes = pdbFile.getBytes();
105110

106111
PDBFileParser parser = new PDBFileParser();
107112

113+
URL mmtfURL = new URL("https://mmtf.rcsb.org/v1.0/full/" + pdbId + ".mmtf.gz");
114+
115+
byte[] mmtfdata = getByteArrayFromInputStream(new GZIPInputStream((mmtfURL.openStream())));
116+
108117
for ( int i =0 ; i< NUMBER_OF_REPEATS ; i++) {
109118

110-
Structure pdbStructure = parser.parsePDBFile(new ByteArrayInputStream(pdbFile.getBytes()));
111-
}
112-
long pdbEnd = System.currentTimeMillis();
119+
long mmtfStart = System.nanoTime();
120+
Structure mmtfStructure = MmtfActions.readFromInputStream(new ByteArrayInputStream(mmtfdata));
121+
long mmtfEnd = System.nanoTime();
113122

114123

115-
URL mmtfURL = new URL("https://mmtf.rcsb.org/v1.0/full/" + pdbId + ".mmtf.gz");
116124

125+
long pdbStart = System.nanoTime();
126+
Structure pdbStructure = parser.parsePDBFile(new ByteArrayInputStream(pdbBytes));
127+
long pdbEnd = System.nanoTime();
117128

118-
byte[] mmtfdata = getByteArrayFromInputStream(new GZIPInputStream((mmtfURL.openStream())));
129+
totalTimePDB += (pdbEnd - pdbStart);
119130

120-
long mmtfStart = System.currentTimeMillis();
121131

122-
for ( int i =0 ; i< NUMBER_OF_REPEATS ; i++) {
123-
Structure mmtfStructure = MmtfActions.readFromInputStream(new ByteArrayInputStream(mmtfdata));
132+
totalTimeMMTF += (mmtfEnd-mmtfStart);
124133
}
125-
long mmtfEnd = System.currentTimeMillis();
126134

127-
long timeMMTF = (mmtfEnd-mmtfStart);
128-
long timePDB = (pdbEnd-pdbStart);
129-
logger.warn("average time to parse mmtf: " + (timeMMTF/NUMBER_OF_REPEATS));
130-
logger.warn("average time to parse PDB : " + (timePDB/NUMBER_OF_REPEATS));
135+
136+
long timePDB = (totalTimePDB/NUMBER_OF_REPEATS);
137+
long timeMMTF = (totalTimeMMTF/NUMBER_OF_REPEATS);
138+
139+
140+
logger.warn("average time to parse mmtf: " + timeMMTF/(1000*1000) + " ms.");
141+
logger.warn("average time to parse PDB : " + timePDB/(1000*1000) + " ms. ");
131142
//
132-
assertTrue( "It should not be the case, but it is faster to parse a PDB file ("+timePDB+" ms.) than MMTF ("+( timeMMTF)+" ms.)!",( timePDB) > ( timeMMTF));
143+
assertTrue( "It should not be the case, but it is faster to parse a PDB file ("+timePDB+" ns.) than MMTF ("+( timeMMTF)+" ns.)!",( timePDB) > ( timeMMTF));
133144
//
134145
}
135146
}

0 commit comments

Comments
 (0)