summaryrefslogtreecommitdiffstats
path: root/contrib/benchmarks/scion/statesPerSecond.js
blob: 2a15fcbb74742899ea7f240f0f7381a3cb31d96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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});

  });
})