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

Faster Rgb to Hsl and Hsv conversions #54

Merged
merged 1 commit into from
Feb 20, 2016
Merged

Faster Rgb to Hsl and Hsv conversions #54

merged 1 commit into from
Feb 20, 2016

Conversation

sidred
Copy link
Contributor

@sidred sidred commented Feb 20, 2016

Faster conversion from Rgb to Hsl and Rgb to Hsv

@sidred
Copy link
Contributor Author

sidred commented Feb 20, 2016

I've added the before and after benchmark and tests code to the benches folder. Let me know if they should be removed.

Rgb to Hsl benchmarks

test rgb_to_hsl_original_f32  ... bench:          14 ns/iter (+/- 2)
test rgb_to_hsl_optimized_f32 ... bench:           9 ns/iter (+/- 1)

test rgb_to_hsl_original_f64  ... bench:          14 ns/iter (+/- 5)
test rgb_to_hsl_optimized_f64 ... bench:           9 ns/iter (+/- 1)

Rgb to Hsv benchmarks

test rgb_to_hsv_original_f32  ... bench:          12 ns/iter (+/- 0)
test rgb_to_hsv_optimized_f32 ... bench:           9 ns/iter (+/- 0)

test rgb_to_hsv_original_f64  ... bench:          12 ns/iter (+/- 1)
test rgb_to_hsv_optimized_f64 ... bench:           9 ns/iter (+/- 1)

@Ogeon
Copy link
Owner

Ogeon commented Feb 20, 2016

Cool! And nice speedup. Are these new algorithms hand crafted or is there a source for them? (just curious) The benchmarks can stay, but how come they aren't using the rgb.into_hsl() and rgb.into_hsv()? Another inlining issue?

@sidred
Copy link
Contributor Author

sidred commented Feb 20, 2016

Are these new algorithms hand crafted or is there a source for them? (just curious)

It started with me noticing that there are unnecessary comparisons for finding both max and min and trying to optimize them.I also a stackoverflow answer that basically said the same, you can find max and min in 3 comparisons instead of 4.

The benchmarks can stay, but how come they aren't using the rgb.into_hsl() and rgb.into_hsv()?

I didn't check with the into_hsl and hsv. I guess because running the benchmarks will then no longer make sense once this is merged.

@Ogeon
Copy link
Owner

Ogeon commented Feb 20, 2016

Yea, it was pretty naive before, since the first goal was to just get the basics down.

I didn't check with the into_hsl and hsv. I guess because running the benchmarks will then no longer make sense once this is merged.

What I meant was to run the into_* as the new algorithm. Thinking more about it makes me realize that these benchmarks will make little sense in the future, unless they are kept as some kind of regression tests. A proper performance test would compare to the previous release, and not just a previous algorithm, so this doesn't really work for that either... May be better to just remove them, after all...

Thank you for including them, anyway. It's nice to see some numbers.

@sidred
Copy link
Contributor Author

sidred commented Feb 20, 2016

Just checked. The trait version is equally fast.

test rgb_to_hsv_optimized_f32 ... bench:           8 ns/iter (+/- 0)
test rgb_to_hsv_optimized_f64 ... bench:          10 ns/iter (+/- 0)
test rgb_to_hsv_original_f32  ... bench:          12 ns/iter (+/- 0)
test rgb_to_hsv_original_f64  ... bench:          12 ns/iter (+/- 1)
test rgb_to_hsv_trait_f32     ... bench:           8 ns/iter (+/- 0)
test rgb_to_hsv_trait_f64     ... bench:          10 ns/iter (+/- 0)

test rgb_to_hsl_optimized_f32 ... bench:           9 ns/iter (+/- 0)
test rgb_to_hsl_optimized_f64 ... bench:           9 ns/iter (+/- 0)
test rgb_to_hsl_original_f32  ... bench:          13 ns/iter (+/- 4)
test rgb_to_hsl_original_f64  ... bench:          13 ns/iter (+/- 4)
test rgb_to_hsl_trait_f32     ... bench:           9 ns/iter (+/- 0)
test rgb_to_hsl_trait_f64     ... bench:           9 ns/iter (+/- 1)

@Ogeon
Copy link
Owner

Ogeon commented Feb 20, 2016

Alright, seems like inlining works as expected in this case.

@sidred
Copy link
Contributor Author

sidred commented Feb 20, 2016

Removed the benches. Should be good to go.

@Ogeon
Copy link
Owner

Ogeon commented Feb 20, 2016

The RgbHue hiccups are probably related to the nested calls, while this is quite shallow. Anyway, I'll inspect this a bit deeper in a moment, but I think the tests has given this an OK stamp, already.

@Ogeon
Copy link
Owner

Ogeon commented Feb 20, 2016

This looks great! Can't find anything to fix here 👍 Thank you!

@homu r+

@homu
Copy link
Contributor

homu commented Feb 20, 2016

📌 Commit cdb4a3f has been approved by Ogeon

@homu
Copy link
Contributor

homu commented Feb 20, 2016

⚡ Test exempted - status

@homu homu merged commit cdb4a3f into Ogeon:master Feb 20, 2016
homu added a commit that referenced this pull request Feb 20, 2016
Faster Rgb to Hsl and Hsv conversions

Faster conversion from Rgb to Hsl and Rgb to Hsv
@sidred sidred deleted the rgb_hsl branch February 20, 2016 13:36
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