-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ethersolve provider to flow benchmarks
- Loading branch information
Showing
6 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ dist/ | |
|
||
target/ | ||
.aider* | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM docker.io/gradle:jdk23 | ||
|
||
WORKDIR /app | ||
COPY ./build.gradle /app/ | ||
COPY ./src/main/java/HelloEtherSolve.java /app/src/main/java/ | ||
RUN gradle build | ||
ENTRYPOINT ["java", "-jar", "/app/build/libs/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
plugins { | ||
id 'java' | ||
id 'application' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
def etherSolveJar = layout.buildDirectory.file('libs/EtherSolve.jar') | ||
|
||
tasks.register('downloadEtherSolve') { | ||
outputs.file etherSolveJar | ||
doLast { | ||
def f = etherSolveJar.get().asFile | ||
f.parentFile.mkdirs() | ||
new URL('https://github.com/SeUniVr/EtherSolve/raw/main/artifact/EtherSolve.jar') | ||
.withInputStream { inputStream -> | ||
f.withOutputStream { it << inputStream } | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation files(etherSolveJar) | ||
implementation 'com.google.code.gson:gson:2.10.1' | ||
} | ||
|
||
tasks.named('compileJava') { | ||
dependsOn 'downloadEtherSolve' | ||
} | ||
|
||
application { | ||
mainClass = 'HelloEtherSolve' | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Main-Class': application.mainClass | ||
} | ||
from { | ||
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } | ||
} | ||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
} |
85 changes: 85 additions & 0 deletions
85
benchmark/providers/ethersolve/src/main/java/HelloEtherSolve.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import parseTree.Contract; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonObject; | ||
|
||
import java.nio.file.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class HelloEtherSolve { | ||
private static final long PROCESS_TIMEOUT_SECONDS = 10; | ||
private final Gson gson = new Gson(); | ||
|
||
private List<Long[]> processContract(String bytecode) { | ||
try { | ||
return new Contract("Sample", bytecode, true) | ||
.getRuntimeCfg() | ||
.getSuccessorsMap() | ||
.entrySet() | ||
.stream() | ||
.flatMap(entry -> entry.getValue().stream() | ||
.map(successor -> new Long[]{entry.getKey(), successor})) | ||
.collect(Collectors.toList()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return List.of(); | ||
} | ||
} | ||
|
||
private List<Long[]> executeWithTimeout(String bytecode) { | ||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
try { | ||
Future<List<Long[]>> future = executor.submit(() -> processContract(bytecode)); | ||
return future.get(PROCESS_TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
} catch (TimeoutException e) { | ||
return List.of(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return List.of(); | ||
} finally { | ||
executor.shutdownNow(); | ||
} | ||
} | ||
|
||
private void processFile(Path file, Map<String, Object[]> results) throws Exception { | ||
if (!Files.isRegularFile(file)) return; | ||
|
||
String content = Files.readString(file); | ||
JsonObject json = gson.fromJson(content, JsonObject.class); | ||
String bytecode = json.get("code").getAsString().substring(2); | ||
|
||
long startTime = System.nanoTime(); | ||
List<Long[]> processResults = executeWithTimeout(bytecode); | ||
long timeMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); | ||
|
||
results.put(file.getFileName().toString(), new Object[]{timeMs, processResults}); | ||
} | ||
|
||
public void execute(String[] args) throws Exception { | ||
if (args.length < 3 || !"flow".equals(args[0])) { | ||
System.out.println("Usage: self flow INPUT_DIR OUTPUT_FILE"); | ||
System.exit(1); | ||
} | ||
|
||
Map<String, Object[]> results = new HashMap<>(); | ||
Path inputDir = Paths.get(args[1]); | ||
Path outputFile = Paths.get(args[2]); | ||
|
||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(inputDir)) { | ||
for (Path file : stream) { | ||
processFile(file, results); | ||
} | ||
} | ||
|
||
Files.writeString(outputFile, gson.toJson(results)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
try { | ||
new HelloEtherSolve().execute(args); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |