Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

scale(), scale_by(), smoothscale(), smoothscale_by() reorganization and speed up#3319

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@itzpr3d4t0r
Copy link
Contributor

@itzpr3d4t0ritzpr3d4t0r commentedJul 17, 2022
edited
Loading

Implements#3315.
Results are a bit strange, but the functions do work. I used this code:

fromtimeitimporttimeitimportpygamefrompygame.transformimportscale,scale_by,smoothscale,smoothscale_bypygame.init()WIDTH,HEIGHT=500,500win=pygame.display.set_mode((WIDTH,HEIGHT))IMAGE=pygame.image.load("images/cell.png").convert()GLOB= {"scale":scale,"IMAGE":IMAGE,"scale_by":scale_by,"smoothscale":smoothscale,"smoothscale_by":smoothscale_by}deftest(test_str:str):print(timeit(test_str,globals=GLOB))print("SCALE: ",end="")test("scale(IMAGE, (100, 100))")print("SCALE_BY: ",end="")test("scale_by(IMAGE, 2.45)")print("SMOOTHSCALE: ",end="")test("smoothscale(IMAGE, (100, 100))")print("SMOOTHSCALE_BY: ",end="")test("smoothscale_by(IMAGE, 2.45)")

and got these results:
OLD

SCALE: 10.217117799999869SCALE_BY: 13.330813199999284SMOOTHSCALE: 17.059421400000247SMOOTHSCALE_BY: 22.5625871000002

NEW

SCALE: 7.131523500000185SCALE_BY: 10.155133100000057SMOOTHSCALE: 16.981359200000043SMOOTHSCALE_BY: 22.357186100000035

Starbuck5 reacted with thumbs up emoji
itzpr3d4t0r added3 commitsJuly 17, 2022 16:02
…o function.transform.smoothscale() and transform.smoothscale_by() now use internal C smoothscale_to function.
@Starbuck5
Copy link
Contributor

Starbuck5 commentedAug 10, 2022
edited
Loading

I didn't measure much of a performance difference at all, I guess this is more of a code quality PR 🙂

Maybe 1.5% better performance in some cases, but the benchmarks are shaky. (Although I've just realized I did test with a large surface, so differences may be masked.)

Copy link
Contributor

@Starbuck5Starbuck5 left a comment

Choose a reason for hiding this comment

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

Besides my formatting nitpicks, this PR looks good to me. It's hard to review though, since the diff is so gnarly. (Not your fault)

Copy link
Contributor

@MyreMylarMyreMylar left a comment

Choose a reason for hiding this comment

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

Had a quick look over the code and it looks reasonable with a bit less duplication.

The tests pass and as far as I can tell it has made little to no difference to performance.

Copy link
Contributor

@Starbuck5Starbuck5 left a comment

Choose a reason for hiding this comment

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

Thanks!

As a final check to make sure outputs hadn't changed, I scaled and smoothscaled a surface into a png file before and after, and verified the file hash hadn't changed.

Copy link
Member

@illumeillume left a comment

Choose a reason for hiding this comment

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

Very nice. 👍
It's common to see different speeds depending on image size and CPU cache size/architecture.

ps, as an aside; have you seehttps://halide-lang.org/ andhttps://github.com/pydata/numexpr ? The videos that halide provides are especially interesting.

@illumeillume added the PerformanceRelated to the speed or resource usage of the project labelAug 20, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@illumeillumeillume left review comments

+2 more reviewers

@MyreMylarMyreMylarMyreMylar approved these changes

@Starbuck5Starbuck5Starbuck5 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Code quality/robustnessCode quality and resilience to changesPerformanceRelated to the speed or resource usage of the projecttransformpygame.transform

Projects

None yet

Milestone

2.1.3

Development

Successfully merging this pull request may close these issues.

Investigate speeding uppygame.transform.scale_by

5 participants

@itzpr3d4t0r@Starbuck5@illume@MyreMylar@ankith26

[8]ページ先頭

©2009-2025 Movatter.jp