Skip to content

Speed-up _complex_sumprod()#1000

Merged
bbayles merged 1 commit intomore-itertools:masterfrom
rhettinger:faster_complex_sumprod
Jun 24, 2025
Merged

Speed-up _complex_sumprod()#1000
bbayles merged 1 commit intomore-itertools:masterfrom
rhettinger:faster_complex_sumprod

Conversation

@rhettinger
Copy link
Copy Markdown
Contributor

Replace generator expressions with equivalent calls to map.

This runs about 40% faster on my Apple M1 Max

@ben42code
Copy link
Copy Markdown
Contributor

ben42code commented Jun 21, 2025

@rhettinger
Measured a performance improvement of 20%

Test env

  • OS: Windows 11
  • Processor: Intel Core i7-11800H
  • Python: 3.13.3 - CPython

Test case

def aRandomComplex():
    return complex((random.random()*10000 - 5000), (random.random()*10000 - 5000))


random.seed(0)
v1 = [aRandomComplex() for _ in range(2000000)]
v2 = [aRandomComplex() for _ in range(2000000)]


def testCase():
    _complex_sumprod(v1, v2)

Perf Measurements

Performed over 50 executions:

Before

min:     0.7268
max:     0.7901
mean:    0.7415
median:  0.7392

After

min:     0.5864
max:     0.6410
mean:    0.5932
median:  0.5918

Performance improvement: 20%

@ben42code
Copy link
Copy Markdown
Contributor

@rhettinger
While checking the performance improvement, I checked if the results differ between the current and new implementation.
Got a perfect match on my large test case✅

@bbayles bbayles merged commit 61de5d2 into more-itertools:master Jun 24, 2025
6 checks passed
@rhettinger rhettinger deleted the faster_complex_sumprod branch June 27, 2025 19:14
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