# Count the actual number of operations performed during run time

Discussion in 'C++' started by junaidnaseer@gmail.com, Apr 29, 2006.

1. ### Guest

Is it possible to actually count the number of addition or
multiplication operations performed in a program during runtime . I
know of a program that does this simply by looking through the code for
* and + operators but the problem is that this program is fooled when
we use if...else structures coz there might be a + in the if part but
the if part of the statement might not be getting actually called in a
particular execution of the program . here is a sample

if ( x==0)
y=y+1;
else
y=y+2;

now upon execution only one plus is executed but the code parsing
technique would give an answer of two which is wrong . I know there is
a way to actually count the number of operations performed during
runtime but i dont quite know how . I have to get this info to some one
else urgent so any one who knows about this plz help !

, Apr 29, 2006

2. ### Peter JanssonGuest

wrote:
> Is it possible to actually count the number of addition or
> multiplication operations performed in a program during runtime . I
> know of a program that does this simply by looking through the code for
> * and + operators but the problem is that this program is fooled when
> we use if...else structures coz there might be a + in the if part but
> the if part of the statement might not be getting actually called in a
> particular execution of the program . here is a sample
>
> if ( x==0)
> y=y+1;
> else
> y=y+2;
>
> now upon execution only one plus is executed but the code parsing
> technique would give an answer of two which is wrong . I know there is
> a way to actually count the number of operations performed during
> runtime but i dont quite know how . I have to get this info to some one
> else urgent so any one who knows about this plz help !
>

How about counting all the operations by inserting code of your own?
For example, like the following;

#ifdef WE_WANT_TO_COUNT_OPS
#endif

if ( x==0)
{
y=y+1;
#ifdef WE_WANT_TO_COUNT_OPS
#endif
}
else
{
y=y+2;
#ifdef WE_WANT_TO_COUNT_OPS
#endif
}

Regards,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/

Peter Jansson, Apr 29, 2006

3. ### Guest

u can delete this post if u want to , in order to cover my stupidity
Peter Jansson wrote:
> wrote:
> > Is it possible to actually count the number of addition or
> > multiplication operations performed in a program during runtime . I
> > know of a program that does this simply by looking through the code for
> > * and + operators but the problem is that this program is fooled when
> > we use if...else structures coz there might be a + in the if part but
> > the if part of the statement might not be getting actually called in a
> > particular execution of the program . here is a sample
> >
> > if ( x==0)
> > y=y+1;
> > else
> > y=y+2;
> >
> > now upon execution only one plus is executed but the code parsing
> > technique would give an answer of two which is wrong . I know there is
> > a way to actually count the number of operations performed during
> > runtime but i dont quite know how . I have to get this info to some one
> > else urgent so any one who knows about this plz help !
> >

>
> How about counting all the operations by inserting code of your own?
> For example, like the following;
>
>
> #ifdef WE_WANT_TO_COUNT_OPS
> #endif
>
> if ( x==0)
> {
> y=y+1;
> #ifdef WE_WANT_TO_COUNT_OPS
> #endif
> }
> else
> {
> y=y+2;
> #ifdef WE_WANT_TO_COUNT_OPS
> #endif
> }
>
>
> Regards,
>
> Peter Jansson
> http://www.p-jansson.com/
> http://www.jansson.net/

, Apr 29, 2006
4. ### Rolf MagnusGuest

wrote:

> u can delete this post if u want to ,

Whoever 'u' is, he probably can't.

Rolf Magnus, Apr 30, 2006