Skip to content

Commit

Permalink
Using Bench builder in Vector/Operations
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jul 18, 2023
1 parent 731a773 commit 74ac8d7
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions test/Benchmarks/src/Vector/Operations.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 74ac8d7

Please sign in to comment.