Skip to content

Commit

Permalink
Benchmark.ips: show allocated bytes per operation (#5522)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and RX14 committed Jan 4, 2018
1 parent aaf7d96 commit ca555d2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/benchmark/ips.cr
Expand Up @@ -43,13 +43,15 @@ module Benchmark
def report
max_label = ran_items.max_of &.label.size
max_compare = ran_items.max_of &.human_compare.size
max_bytes_per_op = ran_items.max_of &.bytes_per_op.to_s.size

ran_items.each do |item|
printf "%s %s (%s) (±%5.2f%%) %s\n",
printf "%s %s (%s) (±%5.2f%%) %s B/op %s\n",
item.label.rjust(max_label),
item.human_mean,
item.human_iteration_time,
item.relative_stddev,
item.bytes_per_op.to_s.rjust(max_bytes_per_op),
item.human_compare.rjust(max_compare)
end
end
Expand Down Expand Up @@ -79,17 +81,25 @@ module Benchmark
GC.collect

measurements = [] of Time::Span
bytes = 0_i64
cycles = 0_i64

target = Time.monotonic + @calculation_time

loop do
bytes_before_measure = GC.stats.total_bytes
elapsed = Time.measure { item.call_for_100ms }
bytes += (GC.stats.total_bytes - bytes_before_measure).to_i64
cycles += item.cycles
measurements << elapsed
break if Time.monotonic >= target
end

ips = measurements.map { |m| item.cycles.to_f / m.total_seconds }
item.calculate_stats(ips)

item.bytes_per_op = (bytes.to_f / cycles.to_f).round.to_i

if @interactive
run_comparison
report
Expand Down Expand Up @@ -139,6 +149,9 @@ module Benchmark
# Multiple slower than the fastest entry
property! slower : Float64

# Number of bytes allocated per operation
property! bytes_per_op : Int32

@ran : Bool
@ran = false

Expand Down

0 comments on commit ca555d2

Please sign in to comment.