Red Artisan

Agile Ruby on Rails Specialists

Core Image Performance

posted by crafterm, 16 Dec 2007

Following my previous post, a few people have asked me how well Core Image performs in comparison to RMagick and ImageScience when used as part of Attachment Fu. To answer these questions, I’ve spent a bit of time collecting some performance results.

Please note that as with all performance testing, results will vary according to many parameters such as hardware, processing power, and even the input image content itself, as you’ll see below.

Naturally Core Image should be faster since it will run hardware accelerated on my MacBook Pro, so please take these results more as an indication of library characteristics rather than final timings. The tests I performed also mirrored how each library was being invoked by Attachment Fu, and beyond performance there’s also several other tangible benefits to Core Image such as deployment and access via RubyCocoa to keep in mind as well.

The first test performs 5 successive resizes of a 1mb image under each library (from 1250x833 to 640x480). The input image is a complex photo (smaller version above) taken in Berlin of parts of the Berlin Wall, including a high colour range and lots of shapes and sizes:

Both RMagick and ImageScience yield consistent results as expected. Core Image’s resize values are interesting as successive resizes are twice as fast than the first, which I speculate would include an initial Core Image to OpenGL compilation phase of the resize operation being performed.

Similar characteristics can be observed with a slightly larger image size of around 2.5mb (2200x1467 to 640x480):

In both cases, Core Image performs really well, particularly on consecutive runs.

The actual image content being resized also affects results as well - the following test uses a blank image of identical dimensions to the 1mb Berlin image (1250x833 to 640x480):

Finally, the following graph shows the results of resizing 6 versions of the Berlin image with each library, at increasing size & dimensions to half their original size. The results plotted for each measurement are calculated over the average of 5 resizes of each image.

At small image sizes, we can see the difference in resize time to be essentially negligible, however as image size increase up to 500kb, the hardware acceleration of Core Image starts to shine, particularly around the 2.5mb - 5mb range and beyond where it screams along.

There does seem to be a limit to performance gains, on Friday Ben and I also made a few experiments with really large image sizes (TIFF files around 90mb, resizing from 5436x4080 to 640x480), and noticed that Core Image can be slower than Image Science under these conditions:

At this stage I can only speculate as to why this occurs, and it deserves further inspection.

Another interesting aspect to look at is the actual on disk size of the resized images. The following is a directory listing of the results after the 2.5mb image (2200x1467 resize to 640x480):

crafterm  staff  153492 16 Dec 22:30 core_image-complex_resized.jpg
crafterm  staff  288455 16 Dec 22:30 image_science-complex_resized.jpg
crafterm  staff  356827 16 Dec 22:30 rmagick-complex_resized.jpg

Core Image’s default compression range is quite impressive, and while I’m sure the other libraries compression factors can be fine tuned I suspect it would also affect their relative performance measurements.

All measurements shown in the graphs are in seconds, and the test machine was my MacBook Pro, 15” Intel Core 2 Duo, 2.16 Ghz with an ATI Radeon X1600 video card with 128mb vram. I’d certainly be keen to see how other types of hardware perform, so please feel free to run the test code on your system and send me the resultant graphs, and I’ll add them to the project.

All test code and input images (except for the 90mb example due to copyright) are available in a git repository online.

Comments

  1. Alex JohnsonDecember 21, 2007 @ 08:42 AM

    Excellent article! I’d done some work with rmagick before and was never quite pleased with how it worked. Like you, I was also intrigued by the possibility of using native Cocoa APIs from within Ruby apps, specifically Core Image.

    Here’s some screenshots of a project I’ve been working on that uses RubyCocoa and Core Image to do server-side image processing for a multi-user photo management app: http://ionize.org/webphoto2/

    I’ve been very pleased with how well the combination of RubyCocoa and Core Image works. Glad to see some speed comparisons to show that it’s very performant when compared to the other obvious alternatives.

    Thanks for sharing your findings!

  2. Jerome Gravel-NiquetDecember 27, 2007 @ 08:12 AM

    Wow, great article.

    I’m also quite intrigued as to why with the 90 mb, CoreImage takes considerably more time than the other 2 to process the manipulation…

    All of this simply opens so many doors. That was just a little affirmation to make all of you think ;)

    Jerome.

  3. JamesJanuary 06, 2008 @ 08:19 AM

    Core Image uses the graphics hardware, so your limited by graphics card memory and things. I would imagine 90meg is past some limitation of the hardware so would be much slower.

    If I remember rightly the Apple Motion documentation talks about this a lot

  4. Constant DupuisJanuary 16, 2008 @ 09:11 PM

    Hi !

    Great article, I’m looking to process huge bunch of images for resizing. So I’m exited about Core Image.

    But I’m new to Git. I install it but cannot figure how to get the samples from your git rep ….

    I try the clone command

    git clone git://git.redartisan.com/projects/afci.git afci

    but nothing append.

    Could you give me advises about that ?

    Thanks

    Constant

  5. Marcus CrafterJanuary 16, 2008 @ 10:47 PM

    Hi Constant,

    Thanks for the information. The repository location required a ‘git’ rather than ‘projects’, however I’ve updated the server so that you should be able to clone the project using the following command:

    git clone git://git.redartisan.com/af_ci

    and

    git clone git://git.redartisan.com/af_ci_extras

    Please let me know if there’s any further issues.

    I’m also in the process of wrapping the image manipulation code into a gem that is registered at rubyforge - this will also make it easier to get a hold of the code and use it for tasks you describe.

    Hope this helps.

    Cheers

    Marcus

  6. Holli GarrisonJune 20, 2008 @ 06:18 AM

    multipara trichroic coosuc spiritous koleroga ommatophore tickproof figural Ossi Kuschnerait - Coldwell Banker Home & Family http://www.orednet.org/~bcasselb/web_1/photo5.html/InfraRed/photos5g.html

Post a comment