#!/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 flows_railway_ten_steps = FlowsRailwayTenSteps.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}_operaion") result = RubyProf.profile do 10_000.times do FlowsRailwayTenSteps.new end end printer = RubyProf::MultiPrinter.new(result) printer.print(path: 'profile', profile: "#{build_output_name}_railway") 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}_operation") result = RubyProf.profile do 10_000.times { flows_railway_ten_steps.call } end printer = RubyProf::MultiPrinter.new(result) printer.print(path: 'profile', profile: "#{exec_output_name}_railway") # # 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}_operation.json", JSON.generate(result)) result = StackProf.run(mode: :wall, raw: true) do 10_000.times do FlowsRailwayTenSteps.new end end File.write("profile/#{build_output_name}_railway.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}_operation.json", JSON.generate(result)) result = StackProf.run(mode: :wall, raw: true) do 10_000.times do flows_railway_ten_steps.call end end File.write("profile/#{exec_output_name}_railway.json", JSON.generate(result)) puts puts 'Install speedscope:' puts ' npm i -g speedscope' puts puts "speedscope profile/#{build_output_name}_operation.json" puts "speedscope profile/#{build_output_name}_railway.json" puts "speedscope profile/#{exec_output_name}_operation.json" puts "speedscope profile/#{exec_output_name}_railway.json"