Thread: how can i figure out how mach time each line of code takes ?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    111

    how can i figure out how mach time each line of code takes ?

    good day,...

    when creating an electrical diagram (vhdl code) u can calculate how much time each operation takes.
    where can find this type of data with functions for example :

    Code:
    #include <stdio.h>
    
    int main()
    {
      int variable = 0;
      variable = variable + 1;
      retrurn 0;
    }
    and
    Code:
    #include <stdio.h>
    
    int main()
    {
      int variable = 0;
      variable = 1;
      retrurn 0;
    }
    returned the same time 0.004 ($time foo).
    i know it works the same but here i do deferent operations
    i tried googling for cycle count(didn't get any good answers).

    anyway:
    as said by our prof :
    AND = 2ms to 4ms
    NAND = 4ms.
    Last edited by jabka; 04-30-2007 at 12:46 PM. Reason: @nthony
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    do you know about instruction pipelines? CPU command caches? About optimization compilers? About profilers?

    Do not start low-level code optimization before you learn these things... Time for executing the same C++ line of code will differ greatly on different CPUs, compilers etc. Why do you need to know this before you have a problem?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Quote Originally Posted by jabka View Post
    good day,...
    it was, until I saw your spelling.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    well, when the compiler generates the opcodes,

    Code:
    varibale = varibale + 1;
    turns into something like

    INC EAX;

    while

    Code:
    varibale = 1;
    turns into something like

    MOV EAX , 0x00000001;


    both of which take only a single clock cycle to execute.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Line of data input method
    By larry_2k4 in forum C Programming
    Replies: 2
    Last Post: 04-28-2009, 11:34 PM
  2. Simple question (for you not for me!)
    By antonis in forum C Programming
    Replies: 35
    Last Post: 11-10-2005, 12:41 PM
  3. Can't figure out a line of code...
    By bamera in forum C++ Programming
    Replies: 1
    Last Post: 10-15-2005, 07:11 PM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  5. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM