简体   繁体   中英

Why does this take so long to compile in VCC 2003?

My team need the "Sobol quasi-random number generator" - a common RNG which is famous for good quality results and speed of operation. I found what looks like a simple C implementation on the web . At home I was able to compile it almost instantaneously using my Linux GCC compiler.

The following day I tried it at work: If I compile in Visual Studio in debug mode it takes about 1 minute. If I were to compile it in release mode it takes about 40 minutes.

Why?

I know that "release" mode triggers some compiler optimization... but how on earth could a file this small take so long to optimize? It's mostly comments and static-data. There's hardly anything worth optimizing.

None of these PCs are particularly slow, and in any case I know that the compile time is consistent across a range of Windows computers. I've also heard that newer versions of Visual Studio have a faster compile time, however for now we are stuck with Visual Studio.Net 2003. Compiling on GCC (the one bundled with Ubuntu 8.04) always takes microseconds.

I'm using VC++ 2003 and it compiled instantly in both debug/release modes.

Edit:

Do you have the latest service pack installed on your systems?

To be honest, I'm not really sure the codes that good. It's got a nasty smell in it. Namely, this function:

unsigned int i4_xor ( unsigned int i, unsigned int j )

//****************************************************************************80
//
//  Purpose:
//
//    I4_XOR calculates the exclusive OR of two integers.
//
//  Modified:
//
//    16 February 2005
//
//  Author:
//
//   John Burkardt
//
//  Parameters:
//
//    Input, unsigned int I, J, two values whose exclusive OR is needed.
//
//    Output, unsigned int I4_XOR, the exclusive OR of I and J.
//
{
  unsigned int i2;
  unsigned int j2;
  unsigned int k;
  unsigned int l;

  k = 0;
  l = 1;

  while ( i != 0 || j != 0 )
  {
    i2 = i / 2;
    j2 = j / 2;

    if ( 
      ( ( i == 2 * i2 ) && ( j != 2 * j2 ) ) ||
      ( ( i != 2 * i2 ) && ( j == 2 * j2 ) ) )
    {
      k = k + l;
    }

    i = i2;
    j = j2;
    l = 2 * l;
  }

  return k;
}

There's an i8_xor too. And a couple of abs functions.

I think a post to the DailyWTF is in order.

EDIT: For the non-c programmers, here's a quick guide to what the above does:

function xor i:unsigned, j:unsigned
  answer = 0
  bit_position = 1
  while i <> 0 or j <> 0
    if least significant bit of i <> least significant bit of j
      answer = answer + bit_position 
    end if
    bit_position = bit_position * 2
    i = i / 2
    j = j / 2
  end while
  return answer
end function

To determine if the least significant bit is set or cleared, the following is used:

bit set if i <> (i / 2) * 2
bit clear if i == (i / 2) * 2

What makes the code extra WTFy is that C defines an XOR operator, namely '^'. So, instead of:

result = i4_xor (a, b);

you can have:

result = a ^ b; // no function call at all!

The original programmer really should have know about the xor operator. But even if they didn't (and granted, it's another obfuscated C symbol), their implementation of an XOR function is unbelievably poor.

I would recommend you download a trial edition of Visual Studio 2008 and try the compile there, just to see if the problem is inherent. Also, if it does happen on a current version, you would be able to report the problem, and Microsoft might fix it.

On the other hand, there is no chance that Microsoft will fix whatever bug is in VS2003.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM