ColdFusion and .NET: Comparing the Performance of Image Resizing

Mar

10

by Mike Fleming at 7:28 am (10 Comments) .NET, ColdFusion


I received a comment from a reader named Daniel yesterday asking if I knew the performance difference in ColdFusion and .NET when resizing an image.  I did not know the answer, so I decided to spend a few minutes and run some tests.  I ran the code on the same server and used the exact same image to test the resize with.  Both pieces of code resized this image to 250 pixels.  The original width of the image was 660 pixels.  The ColdFusion code used a standard CFIMAGE call and the .NET code used the function I blogged out previously.  To test the time in milliseconds I used the GetTickCount function in ColdFusion and the Stopwatch class in .NET.  The timers were both started the line before the resize code and stopped the line after.  The performance difference was a little surprising.  The C# code perfomed much faster than the ColdFusion code.  Granted we are talking about milliseconds here, but even with that said the gap was quite large.  I ran each piece of code five times and took the average across those 5 requests:

ColdFusion: 453 milliseconds
.NET (C#): 66 milliseconds

I was very surprised at these results.  I then was curious to how things would look if I passed in a very large image.  I chose an image with an original width of 1680 pixels and resized it down to 250 pixels.  Those test results are:

ColdFusion: 1891 milliseconds
.NET (C#): 150 milliseconds

So using a different image the performance difference was still quite a large gap. 

I am curious now if I save out the C# code into a class and call it via ColdFusion, if that code would perform faster than using CFIMAGE.  Maybe another blog entry can try that out soon.


Categories .NET, ColdFusion | Tags:

10 Responses to “ColdFusion and .NET: Comparing the Performance of Image Resizing”

  1. Aaron Longnion

    March 10, 2009
    8:11 am

    Interesting.
    Could you post the actual CF code?
    And what if you try ImageResize(), with interpolation of highestPerformance?
    http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_h-im_39.html#5171309

  2. Ed Tabara

    March 10, 2009
    9:06 am

    nice! and definitely it worth trying to do the resize from ColdFusion using the .Net
    It’s not really surprising that C# code was much much faster than Java one, so having knowing ways to do same things with natural CF and using .Net libraries would be a great thing especially for those who run on Windows platform. Plus it would play again for ColdFusion as a strong point and not weakness, because it mean CHOICE.

  3. Eric Cobb

    March 10, 2009
    9:32 am

    This is really interesting, I’ll be watching to see what you find next.
    I think the CF image functions (ImageResize(),ImageWrite(), etc…) might be a better comparison. They give you more control over image attributes. I was able to see significant performance increases when I started tweaking the interpolation parameter of ImageResize().
    Ray did a really good comparison of the different resize options here: http://www.coldfusionjedi.com/index.cfm/2008/11/1/ColdFusion-8-Image-Resize-options

  4. Justin Carter

    March 10, 2009
    10:45 am

    I’d like to see a follow up to this too with regard to the other image functions and the performance of using the .NET object from within ColdFusion. At the moment the app I’m working on still uses an old(er) CFX tag :) Gotta love the wealth of options at our disposal!

  5. Andrew Deren

    March 10, 2009
    12:20 pm

    I’ve noticed the same thing a while ago. I needed to take 3000×3000 pixel images and create small thumbnails out of them. Using CFImage or cf image functions was taking very long time (2-5 seconds), but using .net libraries was only taking 200-300 ms with highest quality settings on both.
    There is definatelly something wrong with CF image processing functions.

  6. radekg

    March 10, 2009
    1:11 pm

    The interesting bit is first image was 660px, second was 1680px.
    ~ 2.5 times bigger.
    First .NET time 66ms, second 150ms. The difference is ~2.5 times.
    In case of CF first time is 453, second was 1891ms what is ~4 times slower.

  7. Paul Cormier

    March 24, 2009
    10:53 am

    I’d be curious to see the results of an identical test of the cfx_imagecr library. I know it’s faster than CF8′s native functions, but I don’t know how it stacks up against the .NET functions.

    http://efflare.com/products/cfx_imagecr/

    I’ve been using it for years, and it creates great-looking images and is very fast.

    • Mike Fleming

      March 24, 2009
      5:46 pm

      I thought about that myself, but do not have that custom tag installed on my server. Prior to CF8 I used that tag quite a bit, and never saw any real issues with it.

  8. Andrew Grosset

    June 1, 2009
    12:56 am

    “save out the C# code into a class and call it via ColdFusion” now that would be neat! I would be interested to see those results.

  9. Andrew Grosset

    June 1, 2009
    12:58 am

    forgot to click the “followup comments” box.

Leave a Reply or Return to Top