-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
38 lines (29 loc) · 1005 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative 'config/application'
Rails.application.load_tasks
task :profile => :environment do
require "stackprof"
fixture = File.read("#{__dir__}/test/fixtures/8_player_large_game.json")
game = Game.from_json(JSON.parse(fixture))
# pre-warm
10.times { MoveDecider.new(game).next_move }
time = Benchmark.ms { 10.times { MoveDecider.new(game).next_move } }
runs = (100000 / time).round
runs = 10 if runs < 10
puts "testing against #{runs} runs"
mode = ENV.fetch("STACKPROF_MODE", "cpu")
puts "Profiling..."
output = "stackprof-#{mode}-snake.dump"
StackProf.run(mode: mode.to_sym, out: output) do
runs.times do
MoveDecider.new(game).next_move
end
end
cmd = "bundle exec stackprof #{output}"
puts cmd
system cmd
end
task simulate: :environment do
Simulation.new.run(verbose: true)
end