Hello,<br><br>I&#39;ve got two very simple programs that draw a very simple picture using cairo, doing a couple hundred thousand of cairo calls.<br>One program is in C++. The other is in Haskell and uses the cairo library bindings.<br>
<br>The C++ program completes in a fraction of a second, the Haskell program takes about 7-8 seconds to run. They produce exactly the same output.<br><br>What could be at fault here? Why are the cairo bindings working so slow? (I suppose there isn&#39;t too much cairo-specific stuff here, perhaps it&#39;s a general FFI question?)<div>
<br></div><div>#include &quot;cairo.h&quot;<br>int main() {<br>    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1024, 768);<br>    cairo_t *cr = cairo_create(surface);<br>    cairo_set_source_rgb(cr, 0, 255, 0);<br>
    for(int x = 0; x &lt; 1024; x += 2) for(int y = 0; y &lt; 768; y += 2) {<br>        cairo_rectangle(cr, x, y, 1, 1);<br>        cairo_fill(cr);<br>    }<br>    cairo_surface_write_to_png(surface, &quot;picture.png&quot;);<br>
    return 0;<br>}<br><br>module Main where<br><br>import qualified Graphics.Rendering.Cairo as C<br>import Control.Monad<br><br>main = C.withImageSurface C.FormatARGB32 1024 768 $ \s -&gt; do<br>  C.renderWith s $ do<br>
    C.setSourceRGBA 0 255 0 255<br>    forM_ [0,2..1024] $ \x -&gt; do<br>      forM_ [0,2..768] $ \y -&gt; do<br>        C.rectangle x y 1 1<br>        C.fill<br>  C.surfaceWriteToPNG s &quot;picture.png&quot;<br><br>-- <br>
Eugene Kirpichov<br>Principal Engineer, Mirantis Inc. <a href="http://www.mirantis.com/">http://www.mirantis.com/</a><br>Editor, <a href="http://fprog.ru/">http://fprog.ru/</a><br><br></div>