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

use an rgba Pix array instead of converting each x,y coord to a Color #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hunterloftis
Copy link

@hunterloftis hunterloftis commented Jul 2, 2019

An illustration of how you might make a more apples-to-apples comparison, with quite different performance characteristics.

~/code/src/github.com/nicolashahn/diffimg-go (master) 🐵  go build ./main.go && time ./main ~/Desktop/test-image-1.png ~/Desktop/test-image-2.png
0.12764707841506104

real	0m3.291s
user	0m3.100s
sys	0m0.197s
~/code/src/github.com/nicolashahn/diffimg-go (master) 🐬  git checkout faster-array
Switched to branch 'faster-array'
Your branch is up to date with 'origin/faster-array'.
~/code/src/github.com/nicolashahn/diffimg-go (faster-array) 🐰  go build ./main.go && time ./main ~/Desktop/test-image-1.png ~/Desktop/test-image-2.png
0.12764707841506104

real	0m1.499s
user	0m1.386s
sys	0m0.131s

@hunterloftis
Copy link
Author

I noticed in the writeup that the Rust version was just iterating through a pixel array while the Go version was iterating through nested X, Y, color-channel values, converting each pixel to a Color, then back to an array of uints. This shows how you can just iterate through the pixels without all that extra work for a significant speedup.

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.

1 participant