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.
Aaron Longnion
March 10, 20098: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
Ed Tabara
March 10, 20099: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.
Eric Cobb
March 10, 20099: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
Justin Carter
March 10, 200910: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!
Andrew Deren
March 10, 200912: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.
radekg
March 10, 20091: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.
Paul Cormier
March 24, 200910: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, 20095: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.
Andrew Grosset
June 1, 200912: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.
Andrew Grosset
June 1, 200912:58 am
forgot to click the “followup comments” box.