File: memory.rb

package info (click to toggle)
ruby-benchmark-memory 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: ruby: 1,121; makefile: 7; sh: 4
file content (31 lines) | stat: -rw-r--r-- 713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require 'benchmark/memory/errors'
require 'benchmark/memory/job'
require 'benchmark/memory/version'

# Performance benchmarking library
module Benchmark
  # Benchmark memory usage in code to benchmark different approaches.
  # @see https://github.com/michaelherold/benchmark-memory
  module Memory
    # Measure memory usage in report blocks.
    #
    # @param quiet [Boolean] A flag to toggle benchmark output.
    #
    # @return [Report]
    def memory(quiet: false)
      raise ConfigurationError unless block_given?

      job = Job.new(quiet: quiet)

      yield job

      job.run
      job.run_comparison
      job.full_report
    end
  end

  extend Benchmark::Memory
end