summaryrefslogtreecommitdiffstats
path: root/test/src/test-performance.cpp
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-07-05 11:35:04 (GMT)
committerGitHub <noreply@github.com>2017-07-05 11:35:04 (GMT)
commitcb2f533085542a753fc45d17fdb09396c46fbadc (patch)
tree66d378d1df7cb82834e944a1f37865809abf75ae /test/src/test-performance.cpp
parent3f10e11d6ad2b97fee4aee6e09bc959ba9b8e0e5 (diff)
parenta0f96c5dd050c524223ac644ba8798bc7cc80bfd (diff)
downloaduscxml-cb2f533085542a753fc45d17fdb09396c46fbadc.zip
uscxml-cb2f533085542a753fc45d17fdb09396c46fbadc.tar.gz
uscxml-cb2f533085542a753fc45d17fdb09396c46fbadc.tar.bz2
Merge pull request #155 from tklab-tud/sradomski
More performant monitors with slight API break
Diffstat (limited to 'test/src/test-performance.cpp')
-rw-r--r--test/src/test-performance.cpp70
1 files changed, 47 insertions, 23 deletions
diff --git a/test/src/test-performance.cpp b/test/src/test-performance.cpp
index 4142b9d..c312b70 100644
--- a/test/src/test-performance.cpp
+++ b/test/src/test-performance.cpp
@@ -1,5 +1,7 @@
#include "uscxml/config.h"
#include "uscxml/Interpreter.h"
+#include "uscxml/interpreter/InterpreterMonitor.h"
+#include "uscxml/util/DOM.h"
#include <chrono>
#include <iostream>
@@ -7,40 +9,62 @@
using namespace uscxml;
using namespace std::chrono;
+long iterations = 0;
+long initMs = 0;
+bool exitPerf = false;
+system_clock::time_point now;
+system_clock::time_point start;
+system_clock::time_point report;
+system_clock::time_point endTime;
+
+class PerfMon : public InterpreterMonitor {
+public:
+ virtual void beforeEnteringState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
+ if (stateName == "mark") {
+ iterations++;
+ now = system_clock::now();
+ if (now > report) {
+ report = now + seconds(1);
+ std::cout << initMs << ", " << iterations << std::endl;
+ iterations = 0;
+ }
+ }
+ if (now > endTime) {
+ exitPerf = true;
+ }
+ }
+};
+
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "Expected filename as first parameter" << std::endl;
exit(EXIT_FAILURE);
}
+ {
+ start = system_clock::now();
- Interpreter interpreter = Interpreter::fromURL(argv[1]);
-
- InterpreterState state;
- system_clock::time_point start = system_clock::now();
-
- while((state = interpreter.step()) != InterpreterState::USCXML_INITIALIZED) {}
- system_clock::time_point now = system_clock::now();
-
- std::cout << "init: " << duration_cast<milliseconds>(now - start).count() << "ms" << std::endl;
-
- start = system_clock::now();
- system_clock::time_point endTime = start + seconds(10);
- system_clock::time_point report = start + seconds(1);
+ Interpreter sc = Interpreter::fromURL(argv[1]);
+ sc.step(); // initialize?
- unsigned long iterations = 0;
+ PerfMon mon;
+ sc.addMonitor(&mon);
- while(true) {
now = system_clock::now();
- if (now > endTime)
- break;
+ initMs = duration_cast<milliseconds>(now - start).count();
- interpreter.step();
+ start = now;
+ report = start + seconds(1);
+ endTime = start + seconds(10);
- iterations++;
- if (now > report) {
- report = now + seconds(1);
- std::cout << "steps / sec: " << iterations << std::endl;
- iterations = 0;
+ while(true) {
+ sc.step();
+ if (exitPerf) {
+ goto DONE_AND_EXIT;
+ }
}
}
+DONE_AND_EXIT:
+ return 0;
}