diff --git a/Gemfile b/Gemfile index 77055f2d..18334401 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem "rubocop", require: false gem "sinatra", require: false gem "webrick", require: false gem "stackprof", require: false +gem "benchmark-ips", require: false if Gem::Version.new(RUBY_VERSION) > Gem::Version.new("2.6.0") gem 'typeprof', require: false diff --git a/Gemfile.lock b/Gemfile.lock index dd4dfbdc..d92a2b9a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,7 @@ GEM tzinfo (~> 2.0) zeitwerk (~> 2.3) ast (2.4.2) + benchmark-ips (2.10.0) blue_green_process (0.1.3) coderay (1.1.3) concurrent-ruby (1.1.9) @@ -128,6 +129,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + benchmark-ips procon_bypass_man! pry rake @@ -142,4 +144,4 @@ DEPENDENCIES webrick BUNDLED WITH - 2.2.30 + 2.3.26 diff --git a/benchmarks/README.md b/benchmarks/README.md index 4f884f2a..33ee508f 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -1,6 +1,15 @@ -# benchmark +# Benchmark / Profiler ## Processing プロコンから読み取ったバイナリを加工する処理 -* `ruby benchmarks/bypass.rb` -* `bundle execc stackprof tmp/stackprof.dump` +### Benchmark +```shell +bundle exec ruby benchmarks/bypass_b.rb +``` + +### Profiler + +```shell +bundle exec ruby benchmarks/bypass_profile.rb +bundle exec stackprof tmp/stackprof.dump +``` diff --git a/benchmarks/bypass_b.rb b/benchmarks/bypass_b.rb new file mode 100644 index 00000000..53048432 --- /dev/null +++ b/benchmarks/bypass_b.rb @@ -0,0 +1,71 @@ +require 'benchmark/ips' +require "procon_bypass_man" +require "tempfile" + +setting_content = + <<~EOH + version: 1.0 + setting: |- + enable(:rumble_on_layer_change) + + install_macro_plugin ProconBypassMan::Plugin::Splatoon3::Macro::FastReturn + install_macro_plugin ProconBypassMan::Plugin::Splatoon3::Macro::JumpToUpKey + install_macro_plugin ProconBypassMan::Plugin::Splatoon3::Macro::JumpToRightKey + install_macro_plugin ProconBypassMan::Plugin::Splatoon3::Macro::JumpToLeftKey + install_macro_plugin ProconBypassMan::Plugin::Splatoon3::Macro::SokuwariForSplashBomb + install_mode_plugin ProconBypassMan::Plugin::Splatoon3::Mode::Guruguru + + install_macro_plugin ProconBypassMan::Plugin::Splatoon3::Macro::DaseiCancel + + prefix_keys_for_changing_layer [:zr, :zl, :l] + set_neutral_position 1906, 1886 + + layer :up, mode: :manual do + flip :zr, if_pressed: :zr, force_neutral: :zl + flip :zl, if_pressed: [:y, :b, :zl] + flip :a, if_pressed: [:a] + flip :down, if_pressed: :down + macro ProconBypassMan::Plugin::Splatoon3::Macro::FastReturn, if_pressed: [:y, :b, :down] + macro ProconBypassMan::Plugin::Splatoon3::Macro::JumpToUpKey, if_pressed: [:y, :b, :up] + macro ProconBypassMan::Plugin::Splatoon3::Macro::JumpToRightKey, if_pressed: [:y, :b, :right] + macro ProconBypassMan::Plugin::Splatoon3::Macro::JumpToLeftKey, if_pressed: [:y, :b, :left] + + remap :l, to: :zr + open_macro :shake, steps: [:shake_left_stick_and_toggle_b_for_0_1sec], if_pressed: [:b, :r], force_neutral: [:b] + left_analog_stick_cap cap: 1100, if_pressed: [:zl, :a], force_neutral: :a + open_macro :forward_ikarole, steps: [:forward_ikarole1], if_pressed: [:thumbl], force_neutral: [] + disable_macro :all, if_pressed: :a + disable_macro :all, if_pressed: :zr + macro ProconBypassMan::Plugin::Splatoon3::Macro::DaseiCancel, if_tilted_left_stick: { threshold: 700 }, if_pressed: [:zl] + end + EOH +setting = Tempfile.new +setting.write(setting_content) +setting.rewind +ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) + +# TODO: 設定ファイルがブランクと大盛りの時に違いがあるか +Benchmark.ips do |x| + raw_binary_of_no_action = ["30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000"].pack("H*") + binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_binary_of_no_action) + x.report("no action") do + ProconBypassMan::Processor.new(binary).process + end + + raw_binary_of_changing_layer = "30f281c080c078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000" + binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_binary_of_changing_layer) + x.report("changing layer") do + ProconBypassMan::Processor.new(binary).process + end + + raw_binary_of_pressing_zr = "30f28180800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000" + binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_binary_of_pressing_zr) + x.report("flipping") do + ProconBypassMan::Processor.new(binary).process + end + + # TODO: macro + + + x.compare! +end diff --git a/benchmarks/bypass.rb b/benchmarks/bypass_profile.rb similarity index 100% rename from benchmarks/bypass.rb rename to benchmarks/bypass_profile.rb diff --git a/bin/generate_output_report b/bin/generate_output_report new file mode 100755 index 00000000..616af219 --- /dev/null +++ b/bin/generate_output_report @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "procon_bypass_man" +require "pry" + +# \x30のみ生成する +# Usage: +# $ `generate_output_report x zl y` のように、引数にボタン名を渡す + +no_action_binary = ["30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000"].pack("H*") +user_operation = ProconBypassMan::Procon::UserOperation.new(no_action_binary) + +ARGV.map { |x| x.to_sym }.each do |button| + user_operation.press_button(button) +end + +puts user_operation.binary.unpack.first