Sha256: 04f2b12ab92c1d37f3a5f36fce7c1d846c0842b763af261253c9064b0ae5be84

Contents?: true

Size: 973 Bytes

Versions: 38

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true
require "benchmark/ips"
require "json"
require "memory_profiler"

module Benchmark
  module Runner
    def data
      posts = Post.all.includes(:author).to_a
      posts_50 = posts.first(50).to_a
      { all: posts, small: posts_50 }
    end

    def run(label = nil, time: 10, disable_gc: true, warmup: 3, &block)
      fail ArgumentError.new, "block should be passed" unless block_given?

      GC.start

      if disable_gc
        GC.disable
      else
        GC.enable
      end

      memory_report = MemoryProfiler.report(&block)

      report = Benchmark.ips(time, warmup, true) do |x|
        x.report(label) { yield }
      end

      results = {
        label: label,
        ips: ActiveSupport::NumberHelper.number_to_delimited(report.entries.first.ips.round(2)),
        allocs: "#{memory_report.total_allocated}/#{memory_report.total_retained}"
      }.to_json

      puts results

    end
  end

  extend Benchmark::Runner
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
panko_serializer-0.7.7 benchmarks/benchmarking_support.rb
panko_serializer-0.7.6 benchmarks/benchmarking_support.rb
panko_serializer-0.7.5 benchmarks/benchmarking_support.rb
panko_serializer-0.7.4 benchmarks/benchmarking_support.rb
panko_serializer-0.7.3 benchmarks/benchmarking_support.rb
panko_serializer-0.7.2 benchmarks/benchmarking_support.rb
panko_serializer-0.7.1 benchmarks/benchmarking_support.rb
panko_serializer-0.7.0 benchmarks/benchmarking_support.rb
panko_serializer-0.6.0 benchmarks/benchmarking_support.rb
panko_serializer-0.5.10 benchmarks/benchmarking_support.rb
panko_serializer-0.5.9 benchmarks/benchmarking_support.rb
panko_serializer-0.5.8 benchmarks/benchmarking_support.rb
panko_serializer-0.5.7 benchmarks/benchmarking_support.rb
panko_serializer-0.5.6 benchmarks/benchmarking_support.rb
panko_serializer-0.5.5 benchmarks/benchmarking_support.rb
panko_serializer-0.5.4 benchmarks/benchmarking_support.rb
panko_serializer-0.5.3 benchmarks/benchmarking_support.rb
panko_serializer-0.5.2 benchmarks/benchmarking_support.rb
panko_serializer-0.5.1 benchmarks/benchmarking_support.rb
panko_serializer-0.5.0 benchmarks/benchmarking_support.rb