Sudden speed up in a C# program

C

Clive Tooth

For the last few months I have been running a processor-intensive
program which I wrote in C# and which is called Zeros6.

The approximate elapsed time, so far, has been 157 days and the total
processor time is 1,217 days. [Some details of the computer: Intel
Core i7 2600 / 3.4 GHz / 4 cores + hyperthreading -> 8 processors.]

I wrote the program using Visual Studio Express 2010 and version 4 of
the .NET Framework (I think).

Anyway, today I decided to install Visual Studio Express 2012. The
installer installed version 4.5 of the .NET Framework and then
requested a reboot to continue the installation. I stopped the Zeros6
program and OKed the reboot. After the reboot Zeros6 restarted
automatically as usual and the Visual Studio installation continued
and soon finished. I was then shocked to discover that Zeros6 was
running MUCH faster than it usually runs. A speed indicator which is
usually fairly steady at 5.5 (picoseconds per digit) had dropped to
2.0 - I had never seen it lower than 5.34. I then stopped and started
the program a few times, and rebooted the computer again, but the
speed improvement continues to persist. If we call the old speed 100%,
the new speed is 275% !!

I am curious to know what is going on.

All 8 processors spend most of their time doing this...

{
ulong carry = 0;
unchecked
{
for (uint i = startI; i < stopI; i++)
{
ulong m = ((ulong)digits << bigPowerIncrement) | carry;
carry = m/myBase;
if ((digits = (uint)(m - myBase*carry)) < 1000000)
{ // get here about 1 time in 100
h.specials[h.specialCount++] = i;
}
} // i loop
} // unchecked
h.carry = carry;
}

Some declarations...

uint[] digits;
uint startI;
uint stopI;
public static readonly int bigPowerIncrement = 34;
public static readonly uint myBase = 1000000000;
 
R

RayLopez99

For the last few months I have been running a processor-intensive

program which I wrote in C# and which is called Zeros6.



The approximate elapsed time, so far, has been 157 days and the total

processor time is 1,217 days. [Some details of the computer: Intel

Core i7 2600 / 3.4 GHz / 4 cores + hyperthreading -> 8 processors.]



I wrote the program using Visual Studio Express 2010 and version 4 of

the .NET Framework (I think).



Anyway, today I decided to install Visual Studio Express 2012. The

installer installed version 4.5 of the .NET Framework and then

requested a reboot to continue the installation. I stopped the Zeros6

program and OKed the reboot. After the reboot Zeros6 restarted

automatically as usual and the Visual Studio installation continued

and soon finished. I was then shocked to discover that Zeros6 was

running MUCH faster than it usually runs. A speed indicator which is

usually fairly steady at 5.5 (picoseconds per digit) had dropped to

2.0 - I had never seen it lower than 5.34. I then stopped and started

the program a few times, and rebooted the computer again, but the

speed improvement continues to persist. If we call the old speed 100%,

the new speed is 275% !!



I am curious to know what is going on.



All 8 processors spend most of their time doing this...



{

ulong carry = 0;

unchecked

{

for (uint i = startI; i < stopI; i++)

{

ulong m = ((ulong)digits << bigPowerIncrement) | carry;

carry = m/myBase;

if ((digits = (uint)(m - myBase*carry)) < 1000000)

{ // get here about 1 time in 100

h.specials[h.specialCount++] = i;

}

} // i loop

} // unchecked

h.carry = carry;

}



Some declarations...



uint[] digits;

uint startI;

uint stopI;

public static readonly int bigPowerIncrement = 34;

public static readonly uint myBase = 1000000000;


Thanks, that's interesting. I once wrote a quick program that loops and found that as the uP heated up, the calculations seemingly went slower. But that's a physical reason. Like Duniho says perhaps the Visual Studio 2012 NET 4.5 library is somehow more optimal than the Visual Studio 2010 4.0 NETlibrary (I think that's the difference, not 4.0/3.5)

RL
 
A

Arne Vajhøj

For the last few months I have been running a processor-intensive
program which I wrote in C# and which is called Zeros6.

The approximate elapsed time, so far, has been 157 days and the total
processor time is 1,217 days. [Some details of the computer: Intel
Core i7 2600 / 3.4 GHz / 4 cores + hyperthreading -> 8 processors.]

I wrote the program using Visual Studio Express 2010 and version 4 of
the .NET Framework (I think).

Anyway, today I decided to install Visual Studio Express 2012. The
installer installed version 4.5 of the .NET Framework and then
requested a reboot to continue the installation. I stopped the Zeros6
program and OKed the reboot. After the reboot Zeros6 restarted
automatically as usual and the Visual Studio installation continued
and soon finished. I was then shocked to discover that Zeros6 was
running MUCH faster than it usually runs. A speed indicator which is
usually fairly steady at 5.5 (picoseconds per digit) had dropped to
2.0 - I had never seen it lower than 5.34. I then stopped and started
the program a few times, and rebooted the computer again, but the
speed improvement continues to persist. If we call the old speed 100%,
the new speed is 275% !!

I am curious to know what is going on.

All 8 processors spend most of their time doing this...

{
ulong carry = 0;
unchecked
{
for (uint i = startI; i < stopI; i++)
{
ulong m = ((ulong)digits << bigPowerIncrement) | carry;
carry = m/myBase;
if ((digits = (uint)(m - myBase*carry)) < 1000000)
{ // get here about 1 time in 100
h.specials[h.specialCount++] = i;
}
} // i loop
} // unchecked
h.carry = carry;
}

Some declarations...

uint[] digits;
uint startI;
uint stopI;
public static readonly int bigPowerIncrement = 34;
public static readonly uint myBase = 1000000000;


There are some performance improvements in 4.5

See:

http://msdn.microsoft.com/en-us/magazine/hh882452.aspx

but none of the improvements mentioned in that article seems
to fit your description.

There could be other improvements though and maybe your
specific code just got a very big boost from a change.

Are you sure that it is not just something as trivial as
that you have switched from 32 bit to 64 bit CLR when
switching VS version?

Arne
 
R

Registered User

- snip -
All 8 processors spend most of their time doing this...
- snip -

I won't speculate on the discovered performance increase, there are too many
variables. I only glanced at the snippet but the quoted line above raises
questions about processors vs cores. The benefits of parallelism may be worth
investigating.

Design Patterns for Decomposition and Coordination on Multicore Architectures
http://msdn.microsoft.com/en-us/library/ff963553.aspx

regards
A.G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top