Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ベンチマークスクリプトを追加する #228

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -128,6 +129,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
benchmark-ips
procon_bypass_man!
pry
rake
Expand All @@ -142,4 +144,4 @@ DEPENDENCIES
webrick

BUNDLED WITH
2.2.30
2.3.26
15 changes: 12 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -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
```
71 changes: 71 additions & 0 deletions benchmarks/bypass_b.rb
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
18 changes: 18 additions & 0 deletions bin/generate_output_report
Original file line number Diff line number Diff line change
@@ -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