[cairo] Creating A Cairo Context Seems Quite Quick
Lawrence D'Oliveiro
ldo at geek-central.gen.nz
Sat Apr 18 03:30:58 PDT 2015
I just added methods to my Path and Path.Segment types in Qahirah
<https://github.com/ldo/qahirah> to compute extents and return
flattened versions. These create a temporary Cairo context so I can use
its append_path and copy_path_flat calls to do all the work. The
overhead of this doesn’t seem too bad.
As a baseline (on an already-created Cairo context), the Python sequence
ctx.new_path().append_path(path).copy_path_flat()
takes 140µs for a simple rectangular path on my Core i7 (averaged over
100,000 iterations using the Python timeit module), while
ctx.new_path().append_path(path).path_extents
takes 59µs. For the new methods I have added, which create a new context
on every call,
path.flatten()
takes 162µs, while
path.extents
takes 83µs. So the overhead in the former is about 16%, in the latter
about 40%. Well short of the order-of-magnitude-or-more I was
expecting/fearing...
More information about the cairo
mailing list