Skip to content

Instantly share code, notes, and snippets.

@Loschcode
Created November 16, 2020 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Loschcode/4d560ed7994e8df3804eaef204be40c9 to your computer and use it in GitHub Desktop.
Save Loschcode/4d560ed7994e8df3804eaef204be40c9 to your computer and use it in GitHub Desktop.
# report for each
# 0.010811 0.001804 0.012615 ( 0.013084)
# report for reduce
# 0.007351 0.001876 0.009227 ( 0.009232)
n=1000000
Benchmark.bm do |x|
x.report do
puts "report for each"
{}.tap do |metrics|
Sidekiq::DeadSet.new.each do |job|
metrics[job.klass] ||= 0
metrics[job.klass] += 1
end
end.sort_by { |key, value| -value }.to_h
end
x.report do
puts "report for reduce"
Sidekiq::DeadSet.new.reduce({}) do |acc, job|
acc[job.klass] = 0 unless acc[job.klass]
acc.merge("#{job.klass}": acc[job.klass] + 1)
end.sort_by { |key, value| -value }.to_h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment