Skip to content

sortperf.py is broken #116576

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

Closed
pochmann3 opened this issue Mar 10, 2024 · 2 comments
Closed

sortperf.py is broken #116576

pochmann3 opened this issue Mar 10, 2024 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@pochmann3
Copy link
Contributor

pochmann3 commented Mar 10, 2024

Bug report

Bug description:

It's supposed to measure sort speed for different kinds of data, from best to worst case. But currently it shows about the same speed for all kinds, because the same list object is sorted a thousand times. Which means all but the first sort are just sorting the already sorted list. And that dominates the total time, making the first=real sort insignificant.

Oddly it was specifically changed to be this way, here, from

    def _prepare_data(self, loops: int) -> list[float]:
        bench = BENCHMARKS[self._name]
        return [
            bench(self._size, self._random)
            for _ in range(loops)
        ]

to:

    def _prepare_data(self, loops: int) -> list[float]:
        bench = BENCHMARKS[self._name]
        return [bench(self._size, self._random)] * loops

There was even a comment showing that all cases from best to worst now take about the same tiny time 29.2 us, calling it an optimization (and I think it refers to the above change). So is this intentional/desired? I highly doubt that, but if it's a mistake, it's really weird.

The whole update was btw called "Move Lib/test/sortperf.py to Tools/scripts", but in reality it wasn't just moved but completely rewritten. I don't think that was good, in my opinion moves should just be moves, not hide massive changes.

@sobolevn @tim-one

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@pochmann3 pochmann3 added the type-bug An unexpected behavior, bug, or error label Mar 10, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 10, 2024
@sobolevn
Copy link
Member

Indeed, thanks for noticing! 👍

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 11, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 11, 2024
sobolevn added a commit that referenced this issue Mar 11, 2024
…st (GH-116577) (#116582)

gh-116576: Fix `Tools/scripts/sortperf.py` sorting the same list (GH-116577)
(cherry picked from commit 4704e55)

Co-authored-by: Nikita Sobolev <[email protected]>
sobolevn added a commit that referenced this issue Mar 11, 2024
…st (GH-116577) (#116583)

gh-116576: Fix `Tools/scripts/sortperf.py` sorting the same list (GH-116577)
(cherry picked from commit 4704e55)

Co-authored-by: Nikita Sobolev <[email protected]>
@pochmann3
Copy link
Contributor Author

Thanks, looks alright now, both the code fix and the times in the PR comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants