Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify worker_memory calculation in get_total #81

Merged
merged 1 commit into from
Jan 31, 2020

Conversation

JuanitoFatas
Copy link
Contributor

Hello 👋

I was playing with this and notice we could simplify the calculation of workers‘ memory a little bit. This also makes it a little bit faster 💨

☺️

worker is a hash of { "worker" => 94, "worker2" => 95... }, we can call values
and sum instead of map + inject.

This also works when there is no worker:

{}.values.sum => 0

Benchmark.ips do |x|
  x.report("current") { workers.map {|_, mem| mem }.inject(&:+) || 0 }
  x.report("  after") { workers.values.sum }
  x.compare!
end;

Warming up --------------------------------------
             current     8.155k i/100ms
               after    59.066k i/100ms
Calculating -------------------------------------
             current     88.131k (± 5.8%) i/s -    440.370k in   5.015402s
               after    739.807k (±31.1%) i/s -      3.367M in   5.091182s

Comparison:
               after:   739807.1 i/s
             current:    88130.6 i/s - 8.39x  slower
@JuanitoFatas JuanitoFatas reopened this Jan 31, 2020
@schneems schneems merged commit 7dc7683 into zombocom:master Jan 31, 2020
@schneems
Copy link
Member

Thanks!

@JuanitoFatas JuanitoFatas deleted the memory/workers branch February 1, 2020 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants