Clocking a program, and parts of it

This is a discussion on Clocking a program, and parts of it within the C Programming forums, part of the General Programming Boards category; Hullo! I'm quite unexperienced at C, and have a few questions. First, I've written a program that calculates Pi in ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    125

    Question Clocking a program, and pointers to arrays

    Hullo!
    I'm quite unexperienced at C, and have a few questions.
    First, I've written a program that calculates Pi in a simple (and rather idiotic) way, with different levels of optimisation, and I want to clock each method to see how much faster each is. How do I go about this? (C++ specific methods are just fine too)

    I'm also a bit unsure about strings and arrays, but I'll first look up some tutorials and the such. (EDIT) Yes, I've another question: When I want to make a pointer that points to an array of 3 ints, and access it, would this be valid?:

    unsigned int *Arrayptr;
    Arrayptr=(unsigned int *)malloc(sizeof(int)*3);
    *Arrayptr[0]=14278;
    *Arrayptr[2]=*Arrayptr[0]*2;


    (^fictional scenario)

    Thanks for hearing me out.
    Last edited by Boksha; 03-17-2002 at 11:48 AM.

  2. #2
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    #include <time.h>

    U should try using the <time.h> header file;

    look at its function and macros.
    Ünicode¬>world = 10.0£

  3. #3
    kdt
    kdt is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    you can use time() function to learn the calculation time
    ------------------------
    #include <time.h>
    #include <stdio.h>
    void main()
    {long first_time,second_time;
    time(&first_time);
    // your codes that calculate pi
    time(&second_time);
    printf("Calculation time is %ld seconds.",second_time-first_time);
    }
    ------------------------
    but it gives you the difference as seconds
    if you need the calculation time in milliseconds you can study
    ftime() function

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    Alright! That was exactly what I needed. Thanks! I don't think I see the ftime() function anywhere though, but I can probably achieve the same result with the clock() function from the same header.
    long Ticks;
    Ticks=clock();

  5. #5
    kdt
    kdt is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    I'm sorry
    I forgot to say ftime() function(in <sys\timeb.h>) is not a function of ANSI C.
    for dos and unix

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. How to go back to parts of the program?
    By Sharmz in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 11:31 PM
  3. passing bye parts of program
    By ReLiEnThAwK in forum C++ Programming
    Replies: 5
    Last Post: 04-06-2006, 12:02 PM
  4. Need help with some C programs. (VERY Long Post)
    By McFury in forum C Programming
    Replies: 9
    Last Post: 04-30-2004, 12:33 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

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