From 028f97fd12cca9e9cad23ce883c541c59cc7942b Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 27 Jun 2017 13:12:07 +0200 Subject: Prepared benchmarks --- contrib/benchmarks/apache-commons/benchmark.sh | 7 ++ contrib/benchmarks/apache-commons/pom.xml | 24 ++++++ .../java/org/uscxml/benchmark/BenchmarkTest.java | 96 ++++++++++++++++++++++ contrib/benchmarks/lxsc/benchmark.sh | 8 ++ contrib/benchmarks/lxsc/test-performance.lua | 38 +++++++++ test/benchmarks/createBenchmarks.pl | 6 +- test/benchmarks/finalParallel.scxml | 2 +- test/benchmarks/findLCCA.scxml | 2 +- 8 files changed, 180 insertions(+), 3 deletions(-) create mode 100755 contrib/benchmarks/apache-commons/benchmark.sh create mode 100644 contrib/benchmarks/apache-commons/pom.xml create mode 100644 contrib/benchmarks/apache-commons/src/test/java/org/uscxml/benchmark/BenchmarkTest.java create mode 100755 contrib/benchmarks/lxsc/benchmark.sh create mode 100644 contrib/benchmarks/lxsc/test-performance.lua 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 @@ + + 4.0.0 + org.uscxml.benchmark + benchmark + jar + 1.0-SNAPSHOT + benchmark + http://maven.apache.org + + + + org.apache.commons + commons-scxml2 + 2.0-SNAPSHOT + + + junit + junit + 3.8.1 + test + + + 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 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 diff --git a/test/benchmarks/createBenchmarks.pl b/test/benchmarks/createBenchmarks.pl index 088c020..cd5cef7 100755 --- a/test/benchmarks/createBenchmarks.pl +++ b/test/benchmarks/createBenchmarks.pl @@ -40,6 +40,7 @@ sub createFindLCCABenchmark { $$where->{'name'} = 'findLCCA'; $$where->{'type'} = 'scxml'; + $$where->{'datamodel'} = 'null'; $$where->{'intial'} = ""; for (my $i = 1; $i <= $parallelStates; $i++) { $$where->{'initial'} .= "id" . ($i*$nestingDepth) . " "; @@ -84,6 +85,7 @@ sub createFinalParallelBenchmark { $$where->{'name'} = 'finalParallel'; $$where->{'type'} = 'scxml'; + $$where->{'datamodel'} = 'null'; $$where->{'intial'} = ""; $$where->{'children'}[0]->{'type'} = 'parallel'; @@ -111,7 +113,7 @@ sub createFinalParallelNestedFinals { $state->{'type'} = "state"; } $state->{'id'} = "id".$stateId++; - + createFinalParallelNestedFinals(\$state->{'children'}, $amount - 1); push @{$$where}, $state; @@ -172,6 +174,8 @@ sub writeMachine { print $fh ' seed="' . $seed . '"'; print $fh ' name="' . $machine->{'name'} . '"' if $machine->{'name'}; print $fh ' initial="' . $machine->{'initial'} . '"' if $machine->{'initial'}; + print $fh ' xmlns="http://www.w3.org/2005/07/scxml"'; + print $fh ' version="1.0"'; print $fh '>'; foreach (@{$machine->{'children'}}) { diff --git a/test/benchmarks/finalParallel.scxml b/test/benchmarks/finalParallel.scxml index 415c4d2..193fa1c 100644 --- a/test/benchmarks/finalParallel.scxml +++ b/test/benchmarks/finalParallel.scxml @@ -1,5 +1,5 @@ - + diff --git a/test/benchmarks/findLCCA.scxml b/test/benchmarks/findLCCA.scxml index 068057f..290a323 100644 --- a/test/benchmarks/findLCCA.scxml +++ b/test/benchmarks/findLCCA.scxml @@ -1,5 +1,5 @@ - + -- cgit v0.12