From 74ac8d759e54c9880477f06eb8907d83b8107580 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Tue, 18 Jul 2023 18:11:38 +0200 Subject: [PATCH] Using Bench builder in Vector/Operations --- test/Benchmarks/src/Vector/Operations.enso | 47 +++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/test/Benchmarks/src/Vector/Operations.enso b/test/Benchmarks/src/Vector/Operations.enso index bfe31103f89c..53632bec7cf1 100644 --- a/test/Benchmarks/src/Vector/Operations.enso +++ b/test/Benchmarks/src/Vector/Operations.enso @@ -16,31 +16,42 @@ num_iterations = 10 # The Benchmarks ============================================================== -bench = +collect_benches group_builder = random_vec = Utils.make_random_vec vector_size random_vec_2 = Utils.make_random_vec 100000 random_gen = Java_Random.new 123456 - Bench.measure (Base.Vector.new vector_size i->i) "New Vector" iter_size num_iterations - Bench.measure (Base.Vector.new vector_size _->42) "New Constant" iter_size num_iterations - Bench.measure (Base.Vector.new vector_size _->random_gen.nextLong) "New Random" iter_size num_iterations - Bench.measure (Base.Vector.fill vector_size 42) "Fill Constant" iter_size num_iterations - Bench.measure (Base.Vector.fill vector_size random_gen.nextLong) "Fill Random (constant)" iter_size num_iterations - Bench.measure (random_vec + [1]) "Append Single" iter_size num_iterations - Bench.measure (random_vec + random_vec_2) "Append Large" iter_size num_iterations - Bench.measure (random_vec.reduce (+)) "Sum" iter_size num_iterations - Bench.measure ((random_vec.drop (First 20)).reduce (+)) "Drop First 20 and Sum" iter_size num_iterations - Bench.measure ((random_vec.drop (Last 20)).reduce (+)) "Drop Last 20 and Sum" iter_size num_iterations - Bench.measure (random_vec.filter (x -> x % 3 == 1)) "Filter" iter_size num_iterations - Bench.measure (random_vec.filter_with_index (i-> x-> (i+x) % 3 == 1)) "Filter With Index" iter_size num_iterations - - Bench.measure (random_vec . map (x -> x + random_gen.nextLong) . filter (x -> x % 3 == 1)) "Map & Filter" iter_size num_iterations - Bench.measure (random_vec.partition (x -> x % 3 == 1)) "Partition" iter_size num_iterations - Bench.measure (random_vec.partition_with_index (i-> x-> (i+x) % 3 == 1)) "Partition With Index" iter_size num_iterations + bench_measure ~act name _ _ = group_builder.specify name act + + bench_measure (Base.Vector.new vector_size i->i) "New Vector" iter_size num_iterations + bench_measure (Base.Vector.new vector_size _->42) "New Constant" iter_size num_iterations + bench_measure (Base.Vector.new vector_size _->random_gen.nextLong) "New Random" iter_size num_iterations + bench_measure (Base.Vector.fill vector_size 42) "Fill Constant" iter_size num_iterations + bench_measure (Base.Vector.fill vector_size random_gen.nextLong) "Fill Random (constant)" iter_size num_iterations + bench_measure (random_vec + [1]) "Append Single" iter_size num_iterations + bench_measure (random_vec + random_vec_2) "Append Large" iter_size num_iterations + bench_measure (random_vec.reduce (+)) "Sum" iter_size num_iterations + bench_measure ((random_vec.drop (First 20)).reduce (+)) "Drop First 20 and Sum" iter_size num_iterations + bench_measure ((random_vec.drop (Last 20)).reduce (+)) "Drop Last 20 and Sum" iter_size num_iterations + bench_measure (random_vec.filter (x -> x % 3 == 1)) "Filter" iter_size num_iterations + bench_measure (random_vec.filter_with_index (i-> x-> (i+x) % 3 == 1)) "Filter With Index" iter_size num_iterations + + bench_measure (random_vec . map (x -> x + random_gen.nextLong) . filter (x -> x % 3 == 1)) "Map & Filter" iter_size num_iterations + bench_measure (random_vec.partition (x -> x % 3 == 1)) "Partition" iter_size num_iterations + bench_measure (random_vec.partition_with_index (i-> x-> (i+x) % 3 == 1)) "Partition With Index" iter_size num_iterations stateful_fun x = s = State.get Number State.put s+x - Bench.measure (State.run Number 0 <| random_vec.each stateful_fun) "Each" iter_size num_iterations + bench_measure (State.run Number 0 <| random_vec.each stateful_fun) "Each" iter_size num_iterations + +bench = + options = Bench.options . size iter_size . iter num_iterations + + all = Bench.build builder-> + builder.group "Vector Operations" options group_builder-> + collect_benches group_builder + + all . run_main main = bench