Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My guess: you are doing something wrong. I've just compared libjpeg-turbo with gdk.PixbufLoader and found virtually no speed differences. The code I used is below.</p> <p>For the libjpeg-turbo (jpegload.c):</p> <pre><code>#include &lt;assert.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys/time.h&gt; #include &lt;jpeglib.h&gt; void decompress(FILE* fd) { JSAMPARRAY buffer; int row_stride; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&amp;jerr); jpeg_create_decompress(&amp;cinfo); jpeg_stdio_src(&amp;cinfo, fd); jpeg_read_header(&amp;cinfo, TRUE); jpeg_start_decompress(&amp;cinfo); row_stride = cinfo.output_width * cinfo.output_components; buffer = (*cinfo.mem-&gt;alloc_sarray) ((j_common_ptr) &amp;cinfo, JPOOL_IMAGE, row_stride, 1); while (cinfo.output_scanline &lt; cinfo.output_height) { (void) jpeg_read_scanlines(&amp;cinfo, buffer, 1); } jpeg_finish_decompress(&amp;cinfo); jpeg_destroy_decompress(&amp;cinfo); } int main(int argc, char** argv) { long len; FILE *fd; unsigned char *buf; struct timeval start, end; int i; const int N = 100; int delta; /* read file to cache it in memory */ assert(argc == 2); fd = fopen(argv[1], "rb"); fseek(fd, 0, SEEK_END); len = ftell(fd); rewind(fd); buf = malloc(len); assert(buf != NULL); assert(fread(buf, 1, len, fd) == len); gettimeofday(&amp;start, NULL); for(i = 0; i &lt; N; i++) { rewind(fd); decompress(fd); } gettimeofday(&amp;end, NULL); if(end.tv_sec &gt; start.tv_sec) { delta = (end.tv_sec - start.tv_sec - 1) * 1000; end.tv_usec += 1000000; } delta += (end.tv_usec - start.tv_usec) / 1000; printf("time spent in decompression: %d msec\n", delta/N); } </code></pre> <p>For python gdk (gdk_load.py):</p> <pre><code>import sys import gtk import time def decompress(data): pbl = gtk.gdk.PixbufLoader() pbl.write(data, len(data)) pbl.close() return pbl.get_pixbuf() data = open(sys.argv[1]).read() N = 100 start = time.time() for i in xrange(N): decompress(data) end = time.time() print "time spent in decompression: %d msec" % int((end - start) * 1000 / N) </code></pre> <p>Test run results:</p> <pre><code>$ gcc jpegload.c -ljpeg $ ./a.out DSC_8450.JPG time spent in decompression: 75 msec $ python gdk_load.py DSC_8450.JPG time spent in decompression: 75 msec $ identify DSC_8450.JPG DSC_8450.JPG JPEG 3008x2000 3008x2000+0+0 8-bit DirectClass 2.626MB 0.000u 0:00.019 </code></pre> <p>EDIT: and another test, using <code>gi.repostiroy</code> this time:</p> <pre><code>import sys import time from gi.repository import GdkPixbuf def decompress(filename): pb = GdkPixbuf.Pixbuf.new_from_file(filename) return pb N = 100 start = time.time() for i in xrange(N): decompress(sys.argv[1]) end = time.time() print "time spent in decompression: %d msec" % int((end - start) * 1000 / N) </code></pre> <p>And results:</p> <pre><code>$ python gi_load.py DSC_8450.JPG time spent in decompression: 74 msec </code></pre> <p>GdkPixbuf.PixbufLoader using gi.repository is really much MUCH slower then "pure" <code>gtk.gdk</code>. Code:</p> <pre><code>import sys import time from gi.repository import GdkPixbuf def decompress(data): pbl = GdkPixbuf.PixbufLoader() pbl.write(data, len(data)) pbl.close() return pbl.get_pixbuf() data = bytearray(open(sys.argv[1]).read()) N = 100 start = time.time() for i in xrange(N): decompress(data) end = time.time() print "time spent in decompression: %d msec" % int((end - start) * 1000 / N) </code></pre> <p>Results:</p> <pre><code>$ python gi_load.py DSC_8450.JPG time spent in decompression: 412 msec </code></pre> <p>But <code>GdkPixbuf.Pixbuf.new_from_file</code> works as fast as pure C version even using <code>gi.repository</code>, so you are still either doing something wrong, or expecting too much.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload