Total execution time and CPU utilization profile of a C# program that performs a heavy computational task--Major difference between a console applicat

  • Thread starter Thread starter alessandrot60
  • Start date Start date
A

alessandrot60

Guest
I am writing a C# application that performs a heavy computational task. For a typical operation, the code may run for 20 to 40 seconds and may allocate 2 to 4 GB of memory. Currently I don't explicitly use threads or tasks. This is just code working with large data structures in memory, almost no I/O.

The total execution time varies widely depending on how I build the project. If I build it as a console application, the execution time is much larger than if I build it as an ASP.NET application and run it in Visual Studio (IIS Express), everything else being the same. The execution time of each type of application is very consistent from one run to the next.

For example, with certain input data, the console application takes 41 seconds (wall-clock time) to complete an operation whereas the ASP.NET application takes 23 seconds (wall-clock time) to complete the same operation (in both cases, I save the output to a file, so I am sure the program is doing all the work it's expected to do).

When I look at the UserProcessorTime of both applications, I see the following:

- the console application consistently reports a UserProcessorTime of about 40 seconds (a little less than the elapsed real time of 41 seconds, suggesting that the bulk of the work is done by one thread at a time), whereas

- the ASP.NET application consistently reports a UserProcessorTime of about 50 seconds (more than twice as large as the elapsed real time of 23 seconds, suggesting that a lot of work is done in parallel).

But as I said above, I am not using threads or tasks explicitly.

Should I conclude that, in the case of the ASP.NET application running in IIS Express, the .NET framework or the CLR (or whatever it is) is able to parallelize its memory management activities (e.g., the garbage collections), but in the case of the same code built as a console application, they don't try to do the same?

I would like to see my console application finish its job in the same total elapsed time achieved by the ASP.NET application. If it's possible for the latter, shouldn't it be possible for the former as well?

Here are two screenshots from the Resource Monitor. The first one is for the ASP.NET application running in IIS Express (23 seconds elapsed). The second one is for the console application (41 seconds elapsed). In both cases, it's the same code performing the same operation with the same input data.

1612886.png1612887.png

Continue reading...
 
Back
Top