operation count 
Author Message
 operation count

Hi,

Is there any freely available program that would return the operation
count and  memory requirements of a given C application (source code
split across different source files)?

Thanks
Sorel
--



Sat, 18 Jan 2003 03:00:00 GMT  
 operation count

Quote:

> Is there any freely available program that would return the operation
> count and  memory requirements of a given C application (source code
> split across different source files)?

Memory requirements of any program in a sufficiently powerful
programming language are generally impossible to predict, because of
Turing's "Halting Problem". Operation count has that problem, too, if
you meant 'count of operations performed', instead of 'count of
operations present in the source code'.
--

Even if all the snow were burnt, ashes would remain.
--



Sun, 19 Jan 2003 03:00:00 GMT  
 operation count

Quote:

>Is there any freely available program that would return the operation
>count and memory requirements of a given C application (source code
>split across different source files)?

SHORT ANSWER:

If there is, it doesn't always work.

LONG ANSWER:

In general, it is impossible to determine the memory
requirements of a program without running it to completion.

Consider this simple (untested) program:

/*********************************************
Read an entire file from standard input and
write it out to standard output, in reverse.
*********************************************/

#include <stdio.h>

void
reverse(void)
{
   int c;

   c = getchar();
   if (c != EOF) {
      /* We haven't reached the end of input yet,
         so recursively call reverse() to get more.
      */
      reverse();
   }

   /* We've finished reading input and are now popping
      our way out of the recursive calls,
      producing output on the way.
   */
   putch(c);

Quote:
}

int
main(void)
{
   reverse();
   return (0);

Quote:
}

/*********  end of example program  *********/

How much memory does it require?  Every function call
requires some storage (usually on a stack) for information
required to return to the caller (e.g., return address,
saved register values).

The reverse() function calls itself recursively, using a
little more memory with each call.  There is no way to
tell from the source code how deep that recursion may
become, so there is no way to tell how much memory the
program will require.

Recursion isn't the only feature that can lead to
unpredictable memory requirements.  Dynamic memory
allocation can too.

The memory requirements for this example program can be
stated as a linear function of the number of input
characters, but it is possible to create a program whose
behavior is not even predictable in that sense - a program
whose behavior can't be predicted even when its inputs are
known.

There is a famous theoretical problem in computer science
called "The Halting Problem":
   Given a program (including all its input data),
   figure out if it ever finishes running.

Sound easy?  It turns out that _in_general_ it is
impossible - not just hard, _impossible_.

Of course, most real-world programs are special cases that
are deliberately designed to be sure that they do or don't
halt, according to requirements.  (But how often do we see
a program in development unexpectedly contain an infinite
loop?  We try to write software in well-lit clearings, but
the dark forest of intractability is all around,
and beasts of chaos lurk nearer than we ken.)

Even for programs that have predictable memory requirements
(many do), those requirements are implementation-specific.

-- Gary Culp
-- Keil Software (www.keil.com)
--



Sun, 19 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Instrumenting: operations counting ?

2. operation count

3. counting elem. operations

4. Counting floating point operations

5. How can i count numbers in an int or count characters in a string in the

6. Differencies in compilation: a[count++]=count;

7. Counting the clock... (counting clock cycles)

8. count number in an int & count characters in a string

9. Counting bits set in 32 bit word - Population Count.

10. Form count

11. Page count for files

12. .NET Reference counting not working?

 

 
Powered by phpBB® Forum Software