nico7et8 nico7et8 - 6 months ago 59
C Question

Is Cairo Graphics slower in other languages than c? In Haskell for example?

I've been using Cairo Graphics in c for a while and I'd like to use it in a more high-level language (namely Haskell, I've also tried Python). It works but truthfully, I don't have a clear picture in my head on how that works internally.

When my Haskell source is compiled, is the cairo-related part of the object file the same as if it had been compiled from a c source ?


cairo_line_to (cr, 100, 100)
in c be compiled into the same machine code as
LineTo 100 100
in Haskell? Will the performance be the same?


There's some FFI overhead from most languages calling C libraries. It's a small (usually-)constant overhead on each call to a C function, but it will add up if you make lot of calls.

This isn't unique to calling C, for what it's worth. Any crossing of memory management systems does the job. That's why modern OpenGL recommends doing as much as possible in calls that send data to graphics memory in giant blocks, instead of one triangle at a time.