summaryrefslogtreecommitdiffstats
path: root/contrib/benchmarks/scion/statesPerSecond.js
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-07-03 15:04:26 (GMT)
committerStefan Radomski <github@mintwerk.de>2017-07-03 15:04:26 (GMT)
commit19d4e8ae2e472dd364ffeff1e096d3f75d5251c4 (patch)
treef006846b1f4bf207d0c8229b52d4948bb1497b63 /contrib/benchmarks/scion/statesPerSecond.js
parentfbda090a39ad02c937345bee204ca3f77106b2bf (diff)
downloaduscxml-19d4e8ae2e472dd364ffeff1e096d3f75d5251c4.zip
uscxml-19d4e8ae2e472dd364ffeff1e096d3f75d5251c4.tar.gz
uscxml-19d4e8ae2e472dd364ffeff1e096d3f75d5251c4.tar.bz2
BEnchmarks and performance improvements
Diffstat (limited to 'contrib/benchmarks/scion/statesPerSecond.js')
-rw-r--r--contrib/benchmarks/scion/statesPerSecond.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/benchmarks/scion/statesPerSecond.js b/contrib/benchmarks/scion/statesPerSecond.js
new file mode 100644
index 0000000..2a15fcb
--- /dev/null
+++ b/contrib/benchmarks/scion/statesPerSecond.js
@@ -0,0 +1,50 @@
+require('babel-polyfill');
+let scxml = require('scxml');
+
+function nowInMS() {
+ var hrTime = process.hrtime();
+ return hrTime[0] * 1000 + hrTime[1] / 1000000
+}
+
+var args = process.argv.splice(process.execArgv.length + 2);
+var started = nowInMS();
+var initTimeMs;
+
+scxml.pathToModel(args[0], function(err,model){
+ if(err) throw err;
+
+ model.prepare(function(err, fnModel) {
+
+ var iterations = 0;
+ var mark = nowInMS();
+
+ if(err) throw err;
+
+ //instantiate the interpreter
+ var sc = new scxml.scion.Statechart(fnModel);
+
+ initTimeMs = nowInMS() - started;
+
+ sc.registerListener({onEntry : function(stateId) {
+ if (stateId == "mark") {
+ iterations++;
+
+ var now = nowInMS();
+ if (now - mark > 1000) {
+ console.log(initTimeMs + ", " + iterations);
+ mark = now;
+ iterations = 0;
+ }
+
+ }
+ }
+ });
+
+ //start the interpreter
+ sc.start();
+
+ //send the init event
+ sc.gen({name:"init",data:null});
+
+ });
+}) \ No newline at end of file