3

I'm currently examining ImageProcessorCore and I ran into an issue that makes me feel like I'm missing something: On his website the dev shows some benchmarks with a performance that is completely different to the times I measure in my sample program. I have a 2.3 MB (3853x2569) jpg image from which I only want to get the width and height (for now), so I created this little .NET core console test application:

using ImageProcessorCore;
using System;
using System.IO;

namespace ImageProcessorCoreTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (FileStream input = File.OpenRead(@"c:\test\a.jpg"))
            {
                DateTime start = DateTime.Now;
                Image image = new Image(input);

                int w = image.Width;
                int h = image.Height;

                double duration = (DateTime.Now.Subtract(start)).TotalMilliseconds;

                Console.WriteLine("Image size is " + w.ToString() + "x" + h.ToString() + " Pixels (" + duration.ToString() + "ms)");
                Console.ReadLine();
            }
        }
    }
}

This operation takes more than 11 seconds (factor 100 compared the benchmarks mentioned above) for just reading in the image and getting the size. What am I doing wrong?

I'm using version 1.0.0 on Windows 10 Pro 64.

(BTW: My dev machine is an i7-5820K with 16G RAM and a Samsung Pro 950 NVMe drive, so the hardware most probably can't be a bottleneck, I think.)

Update 1: Recompiling ImageProcessorCore and creating a release nuget package that I then use in my (release) sample program unfortunately only brings the duration down to a little over 10 seconds.

Update 2: I just resized the test image (externally) to 2000x1334 pixels. This significantly brought down the time to 849 milliseconds, which is still strange considering the given 56 ms for reading, resizing and writing out again in the dev's benchmark.

Update 3: I now use a test image that I can share with you for testing. The new image is 11416x6380 pixels (11.5 MB) and it takes >17 seconds with above code. You can download it here: http://orig01.deviantart.net/92d3/f/2010/110/7/2/pla_sf_3_by_recon071.jpg

Update 4: When I use the package from the MyGet repository, the time for the latest test image (see Update 3) goes down to 2.4 seconds.

Rob
  • 11,492
  • 14
  • 59
  • 94
  • how big is your test image? – zaitsman Oct 01 '16 at 11:27
  • I have tried your code on [this](http://orig01.deviantart.net/92d3/f/2010/110/7/2/pla_sf_3_by_recon071.jpg) ~11.5 MB jpg file. I used _ImageProcessorCore_ version _1.0.0-alpha1058_ available at [myget](https://www.myget.org/feed/imageprocessor/package/nuget/ImageProcessorCore). My machine is _i5-6200U CPU @ 2.30 GHz, 8 GB RAM, Travelstar Z5K1000 disk drive, running Windows 10 Pro 64 bit_. Though the test image size is much larger than yours, it takes 5 seconds on average. Can you share your test image? – Farhan Nasim Oct 01 '16 at 11:28
  • According to the _ImageProcessorCore_ [package history](https://www.myget.org/feed/imageprocessor/package/nuget/ImageProcessorCore) at myget, the last release was published on _Tue, 27 Sep 2016_. Your version is, however, published on _Sep 30 2016_. Did you collect that from some other source? Consider sharing that as well. – Farhan Nasim Oct 01 '16 at 11:34
  • I'm sorry, the publish date is misleading, of course, because I compiled the package myself and added it to my local repository, so nevermind. I edited my post. I've added another image that I can share with you for testing. I'll also try your image now and let you know what I get. – Rob Oct 01 '16 at 11:42
  • @f.nasim: Your image takes about 17.2 seconds to finish. Really strange... – Rob Oct 01 '16 at 11:45
  • @Robert Your 12.1 MB _test.jpg_ takes just ~3s on average at my environment! Could you tell little bit more about your build environment? Also use the official build from _myget_ once instead of compiling the source yourself. That makes a proper comparison. – Farhan Nasim Oct 01 '16 at 11:52
  • @f.nasim: Ok, the myget version takes 2.4 seconds on the 11.5 MB image you mentioned above (I use that as as test image in the post now). That at least is a value that matches your 5 seconds considering the system used for testing. – Rob Oct 01 '16 at 12:11
  • You should give the new [ImageSharp](https://github.com/JimBobSquarePants/ImageSharp) (New name) version a go from MyGet. It's a lot faster now. – James South Feb 02 '17 at 05:48
  • Thanks, I will have a look! – Rob Feb 02 '17 at 05:50

1 Answers1

3

You get the right performance with the official build, but not with your own obviously means something is wrong with your build parameters. Like you, I cloned the ImageProcessorCore and built my own package. Unsurprisingly, I was also getting poor performance as you did! For your 12.1 MB test.jpg took ~23 seconds (where with the official build it takes ~3s.)

The problem is actually with the build command. The default .NET Core package command (dotnet pack) builds package in Debug configuration. And Debug build has poorer performance as it performs elaborate symbol storage and other auxiliary operations.

I built the package in Release configuration with the following command:

dotnet pack --configuration Release

This time the performance is exactly identical with the official build (~3s for test.jpg!)

Farhan Nasim
  • 773
  • 4
  • 13
  • 1
    Good spot! If you have ImageProcessorCore as another project in the solution (rather than using it as an external reference dll which was built elsewhere) and build the solution in release mode, does it have the same effect? – Andrew Morton Oct 01 '16 at 16:22
  • Though didn't try it,but it is all about the configuration the build engine is using to build the sources. Currently ImageProcessorCore is built with the _.NET Core_ build engine and targeted for _.NET Core_ runtime. If you add it in Visual Studio, it changes to _MSBuild_ and _.NET Framework_ respectively. Both build engines has `Debug` and `Release` configurations. In both cases, however, it can be safely said `Release` build will perform better. – Farhan Nasim Oct 01 '16 at 16:44
  • I think the 3 seconds is all we get for now, at the end it still is alpha software and "cranking up the performance" is one of the topics on the dev's roadmap, so I would like to thank him for his great work so far. I'm not sure if I am experienced enough to tweak the code myself, but I'll definitely try it now. – Rob Oct 02 '16 at 10:48
  • Performance is definitely on the roadmap and is now our primary focus. There's a lot of good stuff happening soon which should improve matters. – James South Oct 24 '16 at 09:58