Skip to content

Instantly share code, notes, and snippets.

@crazymykl
Created February 9, 2016 15:32
Show Gist options
  • Save crazymykl/b526e0ed6b285b3c4e77 to your computer and use it in GitHub Desktop.
Save crazymykl/b526e0ed6b285b3c4e77 to your computer and use it in GitHub Desktop.
A way to count the number of queries the passed block causes.
def count_queries(&blk)
x = 0
counter = -> (*args) { x += 1 }
ActiveSupport::Notifications.subscribed counter, 'sql.active_record', &blk
x
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment