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

This is a discussion on how can i figure out how mach time each line of code takes ? within the C Programming forums, part of the General Programming Boards category; good day,... when creating an electrical diagram (vhdl code) u can calculate how much time each operation takes. where can ...

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

    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,189
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

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, 11:41 AM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21