![]() |
| | #1 |
| Registered User Join Date: Mar 2002
Posts: 109
| 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 | |
| | #2 |
| Registered User 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 | |
| | #3 |
| 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 | |
| | #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 | |
| | #5 |
| 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |