Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write code that will cause long compile times?

I'm working on our continuous integration system, and I'm interested in simulating our systems handling of unexpectedly long compile times. Is there any way to cause the compilation to take a long time to complete? Or perhaps force it into some sort of loop that would take a large amount of time to compile? I'm looking for something as easy as Thread.Sleep() only on the compilation rather than the execution.

How about using preprocessor directives?

Any ideas?

like image 490
The Matt Avatar asked Oct 19 '09 02:10

The Matt


People also ask

How do you increase compilation time?

Use a more modern compiler. Compilers are getting better all the time. They are getting efficient at doing better optimizations and generating better code than ever before all the while taking less time for compilation. Changing the older compiler to a newer one will improve C++ compile time for sure.

Why does code compilation take so long?

Every single compilation unit requires hundreds or even thousands of headers to be (1) loaded and (2) compiled. Every one of them typically has to be recompiled for every compilation unit, because the preprocessor ensures that the result of compiling a header might vary between every compilation unit.

What happens when you write a code and compile it?

A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.

How long does it take to compile C code?

A default compile takes about 0.4 seconds of processor time.


1 Answers

Here's an MSBuild sleep task that should do the trick. Call it from BeforeBuild target in your .csproj file, or wherever is appropriate for your need.

MSBuild Community Tasks also has a Sleep task, so go with that if you need to use some of their other tasks, which I've found very useful.

like image 146
si618 Avatar answered Sep 21 '22 12:09

si618