Skip to content

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

Open
hunterloftis wants to merge 4 commits into
nicolashahn:masterfrom
hunterloftis:faster-array
Open

use an rgba Pix array instead of converting each x,y coord to a Color#2
hunterloftis wants to merge 4 commits into
nicolashahn:masterfrom
hunterloftis:faster-array

Conversation

@hunterloftis
Copy link
Copy Markdown

@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
Copy Markdown
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