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
    #1
    1. Advertising

  2. 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
    int numberOfAdditions(0);
    #endif

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


    Regards,

    Peter Jansson
    http://www.p-jansson.com/
    http://www.jansson.net/
    Peter Jansson, Apr 29, 2006
    #2
    1. Advertising

  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
    > int numberOfAdditions(0);
    > #endif
    >
    > if ( x==0)
    > {
    > y=y+1;
    > #ifdef WE_WANT_TO_COUNT_OPS
    > numberOfAdditions++;
    > #endif
    > }
    > else
    > {
    > y=y+2;
    > #ifdef WE_WANT_TO_COUNT_OPS
    > numberOfAdditions++;
    > #endif
    > }
    >
    >
    > Regards,
    >
    > Peter Jansson
    > http://www.p-jansson.com/
    > http://www.jansson.net/
    , Apr 29, 2006
    #3
  4. Rolf Magnus Guest

    wrote:

    > u can delete this post if u want to ,


    Whoever 'u' is, he probably can't.
    Rolf Magnus, Apr 30, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Perica Milosevic

    action performed bug?

    Perica Milosevic, Nov 4, 2003, in forum: Java
    Replies:
    5
    Views:
    710
    Roedy Green
    Nov 6, 2003
  2. atusc
    Replies:
    1
    Views:
    4,211
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,167
    robert
    Feb 11, 2006
  4. =?Utf-8?B?SklNLkgu?=

    q; not performed during debug

    =?Utf-8?B?SklNLkgu?=, Sep 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    311
    =?Utf-8?B?SklNLkgu?=
    Sep 27, 2006
  5. Replies:
    9
    Views:
    360
    junaidnaseer
    May 10, 2006
Loading...

Share This Page