#!/usr/bin/env ruby # rubocop:disable all require 'bundler/setup' require 'json' require 'ruby-prof' require 'stackprof' require_relative './examples' flows_ten_steps = FlowsTenSteps.new build_output_name = '10steps_build_10k_times' exec_output_name = '10steps_execution_10k_times' # # RubyProf # RubyProf.measure_mode = RubyProf::WALL_TIME puts 'Build with RubyProf...' result = RubyProf.profile do 10_000.times do FlowsTenSteps.new end end printer = RubyProf::MultiPrinter.new(result) printer.print(path: 'profile', profile: build_output_name) puts 'Execution with RubyProf...' result = RubyProf.profile do 10_000.times { flows_ten_steps.call } end printer = RubyProf::MultiPrinter.new(result) printer.print(path: 'profile', profile: exec_output_name) # # StackProf # puts 'Build with StackProf...' result = StackProf.run(mode: :wall, raw: true) do 10_000.times do FlowsTenSteps.new end end File.write("profile/#{build_output_name}.json", JSON.generate(result)) puts 'Execution with StackProf...' result = StackProf.run(mode: :wall, raw: true) do 10_000.times do flows_ten_steps.call end end File.write("profile/#{exec_output_name}.json", JSON.generate(result)) puts puts 'Install speedscope:' puts ' npm i -g speedscope' puts puts "speedscope profile/#{build_output_name}.json" puts "speedscope profile/#{exec_output_name}.json"