Skip to content

Fix O(n2) to be O(n) for generate method#1149

Merged
yukideluxe merged 1 commit intoRubyMoney:mainfrom
pranavbabu:patch-3
Jul 23, 2025
Merged

Fix O(n2) to be O(n) for generate method#1149
yukideluxe merged 1 commit intoRubyMoney:mainfrom
pranavbabu:patch-3

Conversation

@pranavbabu
Copy link
Contributor

ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]
Warming up --------------------------------------
        generate_old   144.000 i/100ms
        generate_new   570.000 i/100ms
Calculating -------------------------------------
        generate_old      1.441k (± 0.7%) i/s  (693.93 μs/i) -      4.464k in   3.097879s
        generate_new      5.576k (± 1.4%) i/s  (179.34 μs/i) -     17.100k in   3.067351s

Comparison:
        generate_new:     5576.0 i/s
        generate_old:     1441.1 i/s - 3.87x  slower

Copy link
Member

@sunny sunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

result = []
remaining_amount = amount

parts_sum = parts.sum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the change from inject to sum 😍

@yukideluxe yukideluxe merged commit 531b435 into RubyMoney:main Jul 23, 2025
6 checks passed
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.

3 participants