[cairo] Performance difference between rgb and rgba with alpha 1.0 ?

Maarten Bosmans mkbosmans at gmail.com
Wed May 12 12:29:29 PDT 2010

2010/5/12 Stuart Axon <stuaxo2 at yahoo.com>:
> Is it worth me doing this:
>    if self._strokecolor[3] == 1:
>        cairo_ctx.set_source_rgb(*self._strokecolor[0:3])
>    else:
>        cairo_ctx.set_source_rgba(*self._strokecolor)
> or is it a waste of python cycles because set_source_rgba will notice that alpha is set to 1.0
> and run the faster path anyway ?

The only way to know for sure is to benchmark it. Basically anything
else is pure speculation. Remember: premature optimization is the root
of all evil.

Having said that, the result of the benchmarking will probably be that
it does not matter in any measurable way.

>  S++


More information about the cairo mailing list