Skip to content

Instantly share code, notes, and snippets.

@artofhuman
Last active October 25, 2016 14:25
Show Gist options
  • Save artofhuman/8ea0f9343bb77938cd03ff16746581cf to your computer and use it in GitHub Desktop.
Save artofhuman/8ea0f9343bb77938cd03ff16746581cf to your computer and use it in GitHub Desktop.
def ind(search_params)
@deliveries = Apress::Notifications::Admin::DeliveriesFinder.new(search_params).call
.paginate(:page => 1, :per_page => 20)
.to_a
@company_counts = Apress::Notifications::Company::SendsLog
.between(search_params[:since], search_params[:till])
.where(delivery_id: @deliveries.flat_map(&:id))
.count(:company_id, distinct: true, group: 'delivery_id')
@total_count = @deliveries.total_entries
@deliveries_stat = Apress::Notifications::Statistics::Model.sends_total_per_period(
@deliveries,
search_params[:since],
search_params[:till]
)
end
def measure(no_gc=false, &block)
if no_gc
GC.disable
else
# collect memory allocated during library loading # and our own code before the measurement
GC.start
end
memory_before = `ps -o rss= -p #{Process.pid}`.to_i / 1024
gc_stat_before = GC.stat
time = Benchmark.realtime do
yield
end
#puts ObjectSpace.count_objects
unless no_gc
GC.start
end
#puts ObjectSpace.count_objects
gc_stat_after = GC.stat
memory_after = `ps -o rss= -p #{Process.pid}`.to_i / 1024
puts({
RUBY_VERSION => {
gc: no_gc ? 'disabled' : 'enabled',
time: time.round(2),
gc_count: gc_stat_after[:count] - gc_stat_before[:count], memory: "%d MB" % (memory_after - memory_before)
}}.to_json)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment