diff options
Diffstat (limited to 'contrib')
5 files changed, 173 insertions, 0 deletions
diff --git a/contrib/benchmarks/apache-commons/benchmark.sh b/contrib/benchmarks/apache-commons/benchmark.sh new file mode 100755 index 0000000..ec312a1 --- /dev/null +++ b/contrib/benchmarks/apache-commons/benchmark.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +# mvn archetype:generate -DgroupId=org.uscxml.benchmark -DartifactId=benchmark -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false + +mvn test
\ No newline at end of file diff --git a/contrib/benchmarks/apache-commons/pom.xml b/contrib/benchmarks/apache-commons/pom.xml new file mode 100644 index 0000000..58f6f14 --- /dev/null +++ b/contrib/benchmarks/apache-commons/pom.xml @@ -0,0 +1,24 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.uscxml.benchmark</groupId> + <artifactId>benchmark</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>benchmark</name> + <url>http://maven.apache.org</url> + + <dependencies> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-scxml2</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/contrib/benchmarks/apache-commons/src/test/java/org/uscxml/benchmark/BenchmarkTest.java b/contrib/benchmarks/apache-commons/src/test/java/org/uscxml/benchmark/BenchmarkTest.java new file mode 100644 index 0000000..0888646 --- /dev/null +++ b/contrib/benchmarks/apache-commons/src/test/java/org/uscxml/benchmark/BenchmarkTest.java @@ -0,0 +1,96 @@ +package org.uscxml.benchmark; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.net.URL; +import java.util.List; + +import org.apache.commons.scxml2.*; + +import org.apache.commons.scxml2.env.SimpleDispatcher; +import org.apache.commons.scxml2.env.SimpleErrorReporter; +import org.apache.commons.scxml2.env.Tracer; +import org.apache.commons.scxml2.io.SCXMLReader; +import org.apache.commons.scxml2.io.SCXMLReader.Configuration; +import org.apache.commons.scxml2.model.CustomAction; +import org.apache.commons.scxml2.model.EnterableState; +import org.apache.commons.scxml2.model.Transition; +import org.apache.commons.scxml2.model.SCXML; +import org.apache.commons.scxml2.model.TransitionTarget; +import org.apache.commons.scxml2.model.EnterableState; +import org.apache.commons.scxml2.model.TransitionTarget; + +/** + * Unit test for simple App. + */ +public class BenchmarkTest extends TestCase { + + class PerformanceListener extends SimpleErrorReporter implements SCXMLListener { + public long iterations = 0; + public long mark = System.currentTimeMillis(); + + public void onEntry(final EnterableState state) { + if (state.getId().equals("p0")) { + iterations++; + long now = System.currentTimeMillis(); + if (now - mark > 1000) { + System.out.println(iterations); + mark = now; + iterations = 0; + } + } + } + public void onExit(final EnterableState state) {} + public void onTransition(final TransitionTarget from, final TransitionTarget to, final Transition transition, String event) {} + + } + + public SCXML parse(final URL url, final List<CustomAction> customActions) throws Exception { + Configuration configuration = new Configuration(null, null, customActions); + SCXML scxml = SCXMLReader.read(url, configuration); + return scxml; + } + + public SCXMLExecutor getExecutor(final SCXML scxml, final Evaluator evaluator, final EventDispatcher eventDispatcher) throws Exception { + PerformanceListener trc = new PerformanceListener(); + SCXMLExecutor exec = new SCXMLExecutor(evaluator, eventDispatcher, null); + exec.setStateMachine(scxml); + exec.addListener(scxml, trc); + return exec; + } + + /** + * Create the test case + * + * @param testName name of the test case + */ + public BenchmarkTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( BenchmarkTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + try { + SCXML scxml = parse(new URL("file:../../../test/benchmarks/findLCCA.scxml"), null); + SCXMLExecutor exec = getExecutor(scxml, null, new SimpleDispatcher()); + exec.go(); + } catch (Exception e) { + System.err.println(e); + assertTrue(false); + } + } +} diff --git a/contrib/benchmarks/lxsc/benchmark.sh b/contrib/benchmarks/lxsc/benchmark.sh new file mode 100755 index 0000000..d0860ad --- /dev/null +++ b/contrib/benchmarks/lxsc/benchmark.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +git clone https://github.com/Phrogz/LXSC.git +cp ../../../test/benchmarks/findLCCA.scxml ./test.scxml + +lua ./test-performance.lua
\ No newline at end of file diff --git a/contrib/benchmarks/lxsc/test-performance.lua b/contrib/benchmarks/lxsc/test-performance.lua new file mode 100644 index 0000000..111fffa --- /dev/null +++ b/contrib/benchmarks/lxsc/test-performance.lua @@ -0,0 +1,38 @@ +#!/usr/bin/env lua + +package.path = 'LXSC/?.lua;' .. package.path + +require 'io' +require 'os' +local LXSC = require 'lxsc' + +local c,t,lxsc = os.clock + +local out = io.open(string.format("results-%s.txt",LXSC.VERSION),"w") +local sum=0 +function mark(msg,t2,n) + local delta = (t2-t)*1000/(n or 1) + sum = sum + delta + out:write(string.format("%25s: %5.2fms\n",msg,delta)) +end + +local xml = io.open("test.scxml"):read("*all") +t = c() +for i=1,20 do lxsc = LXSC:parse(xml) end +mark("Parse XML",c(),20) + +lxsc.onAfterEnter = function(id,kind) + if (id=="id401") then + print("Entered "..kind.." '"..tostring(id).."'") + end +end + +t = c() +lxsc:start() +mark("Start Machine",c()) + + +out:write("----------------------------------\n") +out:write(string.format("%25s: %5.2fms ± 20%%\n","Total time",sum)) + +out:close()
\ No newline at end of file |