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