diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-07-03 15:04:26 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2017-07-03 15:04:26 (GMT) |
commit | 19d4e8ae2e472dd364ffeff1e096d3f75d5251c4 (patch) | |
tree | f006846b1f4bf207d0c8229b52d4948bb1497b63 /contrib/benchmarks/apache | |
parent | fbda090a39ad02c937345bee204ca3f77106b2bf (diff) | |
download | uscxml-19d4e8ae2e472dd364ffeff1e096d3f75d5251c4.zip uscxml-19d4e8ae2e472dd364ffeff1e096d3f75d5251c4.tar.gz uscxml-19d4e8ae2e472dd364ffeff1e096d3f75d5251c4.tar.bz2 |
BEnchmarks and performance improvements
Diffstat (limited to 'contrib/benchmarks/apache')
-rw-r--r-- | contrib/benchmarks/apache/pom.xml | 24 | ||||
-rw-r--r-- | contrib/benchmarks/apache/src/test/java/org/uscxml/benchmark/BenchmarkTest.java | 101 |
2 files changed, 125 insertions, 0 deletions
diff --git a/contrib/benchmarks/apache/pom.xml b/contrib/benchmarks/apache/pom.xml new file mode 100644 index 0000000..58f6f14 --- /dev/null +++ b/contrib/benchmarks/apache/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/src/test/java/org/uscxml/benchmark/BenchmarkTest.java b/contrib/benchmarks/apache/src/test/java/org/uscxml/benchmark/BenchmarkTest.java new file mode 100644 index 0000000..08a9a38 --- /dev/null +++ b/contrib/benchmarks/apache/src/test/java/org/uscxml/benchmark/BenchmarkTest.java @@ -0,0 +1,101 @@ +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 { + + public long initMs = 0; + + 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("mark")) { + iterations++; + long now = System.currentTimeMillis(); + if (now - mark > 1000) { + System.out.println(initMs + ", " + 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 { + long started = System.currentTimeMillis(); + String fileName = System.getenv("USCXML_BENCHMARK"); + SCXML scxml = parse(new URL("file:" + fileName), null); + SCXMLExecutor exec = getExecutor(scxml, null, new SimpleDispatcher()); + initMs = System.currentTimeMillis() - started; + exec.go(); + } catch (Exception e) { + System.err.println(e); + assertTrue(false); + } + } +} |