Is there any way to find what is a size of a code and what is its execution time so I can compare two codes and decide which is better?
For example lets say I want to find the size and execution time of this
Code 1
for(int i=0; i<5; i++)
{
sum+=1;
}
and this
Code 2
for(int i=0; i<=4; i++)
{
sum = sum + 1;
}
to decide which is better (I don't care about this example now). For example the result will be:
Code 1:
Size: ? KB
Time: ? ms
Code 2:
Size: ? KB
Time: ? ms
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
You could either use ANTS Profiler http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/ (payable product but they have a Trial version) or some other Profiler product (ANTS, vTune, OptimizeIt, DevPartner, YourKit, dotTrace) on the market.
You may also intstrument the functions by yourself by setting up some unit tests that execute those 2 functions using a manual StopWatch instrumentation to compare execution time (quicker and less expensive). Unit tests would also allow for assuring that you do not have any regressions on performance if you need to change the implementation later. http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx
var stopWatch = new Stopwatch();
stopWatch.Start();
var result = CallFunction();
stopWatch.Stop();
var executionTime = stopWatch.Elapsed;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With