mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 22:10:15 +03:00
Print average when benchmarking (#3762)
This commit is contained in:
parent
d201959a36
commit
67526ea8eb
@ -1,5 +1,6 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.System
|
||||
import Standard.Base.Runtime.Ref
|
||||
|
||||
## Measure the amount of time it takes to execute a given computation.
|
||||
|
||||
@ -20,6 +21,7 @@ import Standard.Base.System
|
||||
Bench.measure Examples.get_boolean "foo" iter_size=2 num_iters=1
|
||||
measure : Any -> Text -> Integer -> Integer -> Nothing
|
||||
measure = ~act -> label -> iter_size -> num_iters ->
|
||||
result = Ref.new 0
|
||||
single_call = _ ->
|
||||
x1 = System.nano_time
|
||||
Runtime.no_inline act
|
||||
@ -30,8 +32,12 @@ measure = ~act -> label -> iter_size -> num_iters ->
|
||||
res = iter_size.times single_call
|
||||
avg = avg_list res
|
||||
fmt = (avg / 1000000).format "%.2f"
|
||||
result.put (result.get + avg)
|
||||
IO.println (label + "/iteration:" + act_it_num.to_text + ": " + fmt + "ms")
|
||||
num_iters.times iteration
|
||||
fmt_avg = (result.get / (1000000*num_iters)).format "%.2f"
|
||||
IO.println (label + " average: " + fmt_avg + "ms")
|
||||
|
||||
|
||||
## PRIVATE
|
||||
|
||||
|
@ -32,6 +32,7 @@ main =
|
||||
Bench.measure ((random_vec.drop (Last 20)).sum) "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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user