From 0ae743f4466b1390a24da26c5c55daac74f5e80a Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sat, 7 Jul 2018 02:10:33 +0200 Subject: [PATCH] =?UTF-8?q?Benchmark=20Endg=C3=BCltig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- src/de/dhbwstuttgart/sat/asp/ASPUnify.java | 4 +- .../JavaTXCompilerASPBenchmark.java | 126 +++++++----------- 3 files changed, 50 insertions(+), 82 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 00bf7f61..0a73ef6e 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -155,7 +155,7 @@ public class JavaTXCompiler { writer.close(); ASPUnify clingo = new ASPUnify(Arrays.asList(new File(tempDirectory + "test.lp"))); String result = clingo.runClingo(); - System.out.println(result); + //System.out.println(result); ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(cons)); return Arrays.asList(resultSet); } diff --git a/src/de/dhbwstuttgart/sat/asp/ASPUnify.java b/src/de/dhbwstuttgart/sat/asp/ASPUnify.java index 997d78aa..6b51accd 100644 --- a/src/de/dhbwstuttgart/sat/asp/ASPUnify.java +++ b/src/de/dhbwstuttgart/sat/asp/ASPUnify.java @@ -45,8 +45,8 @@ public class ASPUnify { } commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList())); - commands.stream().forEach(s -> System.out.print(s + " ")); - System.out.println(); + //commands.stream().forEach(s -> System.out.print(s + " ")); + //System.out.println(); Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start(); InputStream output = clingo.getInputStream(); diff --git a/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java b/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java index f0549dc2..d1396f0a 100644 --- a/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java +++ b/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java @@ -1,17 +1,22 @@ package asp.unifywithoutwildcards; import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import org.junit.Test; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -22,92 +27,55 @@ public class JavaTXCompilerASPBenchmark { public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; - @Test - public void finiteClosure() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"fc.jav")); - } - @Test - public void lambda() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Lambda.jav")); - } - @Test - public void lambda2() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Lambda2.jav")); - } - @Test - public void lambda3() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Lambda3.jav")); - } - @Test - public void mathStruc() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"mathStruc.jav")); - } - @Test - public void generics() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Generics.jav")); - } - @Test - public void genericsMethodCall() throws IOException, ClassNotFoundException, InterruptedException { - TestResultSet result = execute(new File(rootDirectory+"MethodCallGenerics.jav")); - //TODO: Hier sollte der Rückgabetyp der Methode String sein - } - @Test - public void faculty() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Faculty.jav")); - } - @Test - public void facultyTyped() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"FacultyTyped.jav")); - } - @Test - public void matrix() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Matrix.jav")); - } - @Test - public void matrixTest() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"MatrixTest.jav")); - } - @Test - public void packageTests() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Package.jav")); - } @Test public void vector() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Vector.jav")); - } - @Test - public void lambdaRunnable() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"LambdaRunnable.jav")); - } - @Test - public void expressions() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Expressions.jav")); - } - @Test - public void addLong() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"AddLong.jav")); - } + //execute(new File(rootDirectory+"Vector.jav")); + List> benchmarkUnifyResults = new ArrayList<>(); + for(int numAdds = 1; numAdds <= 15; numAdds++){ - private static class TestResultSet{ + String tmpFile = "/tmp/vector.jav"; + PrintWriter writer = new PrintWriter(tmpFile, "UTF-8"); + writer.println("import java.util.ArrayList;"); + writer.println("import java.util.Vector;"); + writer.println("import java.lang.Object;"); + writer.println("class MyVector{"); + writer.println("id(x){"); + writer.println("Object i;"); + for(int i = 0; i< numAdds; i++) + writer.println("x.add(i);"); + writer.println("return x;"); + writer.println("}}"); + writer.close(); - } + List results = new ArrayList<>(); + List resultsTotal = new ArrayList<>(); + for(int i = 0; i < 20 ; i++){ + Date d1 = new Date(); + JavaTXCompiler compiler = new JavaTXCompiler(new File(tmpFile)); - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InterruptedException { - List results = new ArrayList<>(); - for(int i = 0; i < 20; i++){ - Date d1 = new Date(); - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + Date du1 = new Date(); + compiler.aspTypeInference(); + Date du2 = new Date(); - compiler.aspTypeInference(); - - Date d2 = new Date(); - long seconds = (d2.getTime()-d1.getTime())/1000; - results.add("Total: "+seconds + " Sekunden"); + Date d2 = new Date(); + if(i > 4){ + long milliseconds = (du2.getTime()-du1.getTime()); + results.add(milliseconds); + milliseconds = (d2.getTime()-d1.getTime()); + resultsTotal.add(milliseconds); + } + } + benchmarkUnifyResults.add(results); } - for(String result : results){ - System.out.println(result); + + for(int y = 0; y < benchmarkUnifyResults.get(0).size(); y++){ + for(int x = 0; x < benchmarkUnifyResults.size(); x++){ + long value = benchmarkUnifyResults.get(x).get(y); + System.out.print(value + " "); + } + System.out.println(); } - return new TestResultSet(); + } static String readFile(String path, Charset encoding)