C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-17-2002, 08:17 AM   #1
Registered User
 
Join Date: Mar 2002
Posts: 109
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 12:48 PM.
Boksha is offline   Reply With Quote
Old 03-17-2002, 01:38 PM   #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£
bljonk is offline   Reply With Quote
Old 03-17-2002, 04:04 PM   #3
kdt
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
kdt is offline   Reply With Quote
Old 03-18-2002, 08:06 AM   #4
Registered User
 
Join Date: Mar 2002
Posts: 109
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();
Boksha is offline   Reply With Quote
Old 03-18-2002, 06:02 PM   #5
kdt
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
kdt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:12 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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