summaryrefslogtreecommitdiffstats
path: root/test/src/test-performance.cpp
diff options
context:
space:
mode:
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;
}