Skip to content

Instantly share code, notes, and snippets.

@pbyrne
Created September 10, 2012 18:38
Show Gist options
  • Save pbyrne/3692815 to your computer and use it in GitHub Desktop.
Save pbyrne/3692815 to your computer and use it in GitHub Desktop.
Ack! Performance!
# setup from controller and model code
params = {game_id: 3598462, play_by_play_string: true}
sort_order = [:play_index, :asc]
plays = Play.where(:game_id => params[:game_id]).order_by(sort_order)
plays = plays.first.class.prune_plays(plays)
methods = [:initial_screen]
play_by_play_string = params[:play_by_play_string]
if play_by_play_string
methods = plays.first.class.play_by_play_methods
end
# => [:initial_screen, :play_by_play_string, :scoring_play_string, :clock_time_string, :home_team_score, :away_team_score, :special_tags, :time_interval, :play_summary, :team_id, :down_string, :ball_on_string, :pos_team_id, :starting_yard_line, :ending_yard_line, :distance, :scoring_team_id]
# the meat of the issue
methods.each do { |m| puts "-------"; puts m; s = Time.now; plays.as_json(:methods => [m]); e = Time.now; puts e - s; }
output = <<EOF
-------
initial_screen
1.024383301
-------
play_by_play_string
1.281472832
-------
scoring_play_string
1.733567307
-------
clock_time_string
0.862705006
-------
home_team_score
1.299178866
-------
away_team_score
1.903250648
-------
special_tags
1.588877688
-------
time_interval
0.776766675
-------
play_summary
1.531592147
-------
team_id
0.90151818
-------
down_string
44.307081816
-------
ball_on_string
21.023035193
-------
pos_team_id
0.968410424
-------
starting_yard_line
23.231218178
-------
ending_yard_line
1.392813954
-------
distance
22.25677171
-------
scoring_team_id
1.306947723
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment