tests: In test-encode-decode-benchmark, pass the encoding into the decode benchmark functions.
diff --git a/tests/test-encode-decode-benchmark.cpp b/tests/test-encode-decode-benchmark.cpp
index c689f95..0f194be 100644
--- a/tests/test-encode-decode-benchmark.cpp
+++ b/tests/test-encode-decode-benchmark.cpp
@@ -73,16 +73,22 @@
1
};
-static void
-testDataDecodeCpp()
+#if 0
+static Blob
+testEncodeComplexDataCpp()
{
- double nIterations = 1000000;
+}
+#endif
+
+static double
+benchmarkDataDecodeSecondsCpp(int nIterations, const Blob& encoding)
+{
size_t nameSize = 0;
double start = getNowSeconds();
for (int i = 0; i < nIterations; ++i) {
Data data;
- data.wireDecode(Data1, sizeof(Data1));
+ data.wireDecode(*encoding);
nameSize = data.getName().size();
}
double finish = getNowSeconds();
@@ -91,14 +97,12 @@
if (nameSize != 2)
throw runtime_error("Unexpected data packet name size");
- cout << "Data decode C++: Duration sec: " << (finish - start) << ", Hz: " << (nIterations / (finish - start)) << endl;
+ return finish - start;
}
-static void
-testDataDecodeC()
+static double
+benchmarkDataDecodeSecondsC(double nIterations, uint8_t *encoding, size_t encodingLength)
{
- double nIterations = 20000000;
-
size_t nameSize = 0;
double start = getNowSeconds();
for (int i = 0; i < nIterations; ++i) {
@@ -110,13 +114,13 @@
keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
ndn_BinaryXmlDecoder decoder;
- ndn_BinaryXmlDecoder_initialize(&decoder, Data1, sizeof(Data1));
+ ndn_BinaryXmlDecoder_initialize(&decoder, encoding, encodingLength);
size_t signedPortionBeginOffset, signedPortionEndOffset;
ndn_Error error;
if ((error = ndn_decodeBinaryXmlData(&dataStruct, &signedPortionBeginOffset, &signedPortionEndOffset, &decoder)))
{
cout << "Error in ndn_decodeBinaryXmlData: " << ndn_getErrorString(error) << endl;
- return;
+ return 0;
}
nameSize = dataStruct.name.nComponents;
@@ -127,15 +131,25 @@
if (nameSize != 2)
throw runtime_error("Unexpected data packet name size");
- cout << "Data decode C: Duration sec: " << (finish - start) << ", Hz: " << (nIterations / (finish - start)) << endl;
+ return finish - start;
}
int
main(int argc, char** argv)
{
try {
- testDataDecodeCpp();
- testDataDecodeC();
+ {
+ Blob encoding(Data1, sizeof(Data1));
+
+ int nIterations = 1000000;
+ double duration = benchmarkDataDecodeSecondsCpp(nIterations, encoding);
+ cout << "Data decode C++: Duration sec: " << duration << ", Hz: " << (nIterations / duration) << endl;
+ }
+ {
+ int nIterations = 20000000;
+ double duration = benchmarkDataDecodeSecondsC(nIterations, Data1, sizeof(Data1));
+ cout << "Data decode C: Duration sec: " << duration << ", Hz: " << (nIterations / duration) << endl;
+ }
} catch (std::exception& e) {
cout << "exception: " << e.what() << endl;
}