From 68e057f98ed9d7cbe14ec0a91869789a25d93f38 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 24 Nov 2023 09:05:04 +0100 Subject: [PATCH 1/2] Display error when the execution isn't Success --- test/Benchmarks/src/Startup.enso | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/Benchmarks/src/Startup.enso b/test/Benchmarks/src/Startup.enso index 3d1901f8145c..52f7dbd8dcb8 100644 --- a/test/Benchmarks/src/Startup.enso +++ b/test/Benchmarks/src/Startup.enso @@ -9,11 +9,19 @@ type Data Value ~enso_bin:File ~empty_world:File ~hello_world:File bench_empty self = - res = Process.run self.enso_bin.path [ "--run", self.empty_world.to_text ] + startup self.enso_bin.path [ "--run", self.empty_world.to_text ] bench_hello self = - res = Process.run self.enso_bin.path [ "--run", self.hello_world.to_text ] - + startup self.enso_bin.path [ "--run", self.hello_world.to_text ] + +startup exe:Text args:(Vector Text) = + result = Process.run exe args + case result.exit_code of + Exit_Code.Failure code -> + IO.println "Exit code: "+code + IO.println result.stdout + IO.println result.stderr + Exit_Code.Success -> Nothing collect_benches = Bench.build builder-> options = Bench.options . set_warmup (Bench.phase_conf 2 5) . set_measure (Bench.phase_conf 3 5) From 44b37c7cbcca87f25c38cf2e5b40b6d9bbb2ffe5 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Sat, 25 Nov 2023 08:24:23 +0100 Subject: [PATCH 2/2] Benchmark on files that are already prepared in the repository --- test/Benchmarks/src/Main.enso | 2 +- test/Benchmarks/src/Startup.enso | 60 ----------------- test/Benchmarks/src/Startup/Empty_World.enso | 1 + test/Benchmarks/src/Startup/Hello_World.enso | 3 + test/Benchmarks/src/Startup/Startup.enso | 70 ++++++++++++++++++++ 5 files changed, 75 insertions(+), 61 deletions(-) delete mode 100644 test/Benchmarks/src/Startup.enso create mode 100644 test/Benchmarks/src/Startup/Empty_World.enso create mode 100644 test/Benchmarks/src/Startup/Hello_World.enso create mode 100644 test/Benchmarks/src/Startup/Startup.enso diff --git a/test/Benchmarks/src/Main.enso b/test/Benchmarks/src/Main.enso index 5823d8acc195..1e18ab43cbb1 100644 --- a/test/Benchmarks/src/Main.enso +++ b/test/Benchmarks/src/Main.enso @@ -30,7 +30,7 @@ import project.Number_Parse import project.Numeric import project.Range import project.Sum -import project.Startup +import project.Startup.Startup import project.Runtime.Panics_And_Errors from Standard.Base.Runtime import Debug diff --git a/test/Benchmarks/src/Startup.enso b/test/Benchmarks/src/Startup.enso deleted file mode 100644 index 52f7dbd8dcb8..000000000000 --- a/test/Benchmarks/src/Startup.enso +++ /dev/null @@ -1,60 +0,0 @@ -from Standard.Base import all - -from Standard.Test import Bench - -polyglot java import java.lang.System as Java_System -polyglot java import java.io.File as Java_File - -type Data - Value ~enso_bin:File ~empty_world:File ~hello_world:File - - bench_empty self = - startup self.enso_bin.path [ "--run", self.empty_world.to_text ] - - bench_hello self = - startup self.enso_bin.path [ "--run", self.hello_world.to_text ] - -startup exe:Text args:(Vector Text) = - result = Process.run exe args - case result.exit_code of - Exit_Code.Failure code -> - IO.println "Exit code: "+code - IO.println result.stdout - IO.println result.stderr - Exit_Code.Success -> Nothing - -collect_benches = Bench.build builder-> - options = Bench.options . set_warmup (Bench.phase_conf 2 5) . set_measure (Bench.phase_conf 3 5) - - - data = - Data.Value enso_bin empty_file hello_file - - builder.group "Startup" options group_builder-> - group_builder.specify "empty_startup" data.bench_empty - group_builder.specify "hello_world_startup" data.bench_hello - -empty_file = - f = File.create_temporary_file "empty" "enso" - t = """ - main = "Hello World" - t.write f - f - -hello_file = - f = File.create_temporary_file "hello" "enso" - t = """ - from Standard.Base import IO - - main = IO.println "Hello World" - t.write f - f - -enso_bin = - p = Java_System.getProperty "jdk.module.path" - s = p.split Java_File.separator - paths = s.take (Index_Sub_Range.While _!="..") - j = paths . join Java_File.separator - File.new j / if Platform.os == Platform.OS.Windows then "enso.bat" else "enso" - -main = collect_benches . run_main diff --git a/test/Benchmarks/src/Startup/Empty_World.enso b/test/Benchmarks/src/Startup/Empty_World.enso new file mode 100644 index 000000000000..6e147c44da22 --- /dev/null +++ b/test/Benchmarks/src/Startup/Empty_World.enso @@ -0,0 +1 @@ +main = "Hello World" diff --git a/test/Benchmarks/src/Startup/Hello_World.enso b/test/Benchmarks/src/Startup/Hello_World.enso new file mode 100644 index 000000000000..4e427a9e38f7 --- /dev/null +++ b/test/Benchmarks/src/Startup/Hello_World.enso @@ -0,0 +1,3 @@ +from Standard.Base import IO + +main = IO.println "Hello World" diff --git a/test/Benchmarks/src/Startup/Startup.enso b/test/Benchmarks/src/Startup/Startup.enso new file mode 100644 index 000000000000..51703c32a6e4 --- /dev/null +++ b/test/Benchmarks/src/Startup/Startup.enso @@ -0,0 +1,70 @@ +from Standard.Base import all + +from Standard.Test import Bench + +polyglot java import java.lang.System as Java_System +polyglot java import java.io.File as Java_File + +type Data + Value ~enso_bin:File ~empty_world:File ~hello_world:File + + bench_empty self = + self.startup [ "--run", self.empty_world.to_text ] + + bench_hello self = + self.startup [ "--run", self.hello_world.to_text ] + + startup self args = + exe = self.enso_bin + result = Process.run exe.path args + case result.exit_code of + Exit_Code.Failure code -> + IO.println "Exit code: "+code.to_text + IO.println result.stdout + IO.println result.stderr + Panic.throw "Exit code: "+code.to_text + Exit_Code.Success -> + if result.stdout.contains "Hello World" then Nothing else + msg = "Execution should contain 'Hello World', but:\n====\n" + result.stdout + '\n' + result.stderr + "\n====" + IO.println msg + Panic.throw msg + +collect_benches = Bench.build builder-> + options = Bench.options . set_warmup (Bench.phase_conf 2 5) . set_measure (Bench.phase_conf 3 5) + + + data = + Data.Value enso_bin (find_sibling "Empty_World.enso") (find_sibling "Hello_World.enso") + + builder.group "Startup" options group_builder-> + group_builder.specify "empty_startup" data.bench_empty + group_builder.specify "hello_world_startup" data.bench_hello + +find_sibling name = + f = enso_project.root / "src" / "Startup" / name + if f.is_regular_file.not then Panic.throw "Cannot find "+f.to_text + f + +enso_bin = + find_prefix dir prefix = + vec = dir.list name_filter=prefix+"*" + if vec.length == 1 then vec.at 0 else + msg = "Cannot find " + prefix + "* in" + dir.to_text + "\n" + err = dir.list.fold msg t-> f-> + t + f.to_text + "\n" + Panic.throw err + + project_root = File.new enso_project.root.to_text + repository_root = project_root . parent . parent + built_distribution = find_prefix repository_root "built-distribution" + enso_engine = find_prefix built_distribution "enso-engine-" + enso = find_prefix enso_engine "enso-" + bin = find_prefix enso "bin" + + exe = File.new bin / if Platform.os == Platform.OS.Windows then "enso.bat" else "enso" + + if exe.is_regular_file.not then Panic.throw "Cannot find "+exe.to_text + + exe + +main = collect_benches . run_main