![]() |
| | #1 |
| Registered User Join Date: Jul 2008
Posts: 15
| How to time how long a program takes to run? I have written a C program that is supposed to run in under 2 seconds. Is there a function in C that lets me time how long it takes to run the program? Thanks |
| advancedk is offline | |
| | #2 |
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| I often used clock() in time.h to get the time in millisecs. Only problem with that is that returns the number of clock cycles on linux so you have to divide it by CLOCKS_PER_SEC according to the manpage. Anyway its simple to use: Code: start_time = clock() // do stuff end_time = clock() seconds_elapsed = (end_time - start_time) / 1000;
__________________ Senior highbrow doctor of authority. |
| mike_g is offline | |
| | #3 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,139
| On Linux I'd be using time anyway. Code: [ ~]$ time ./myprog real 0m3.855s user 0m0.057s sys 0m0.297s |
| zacs7 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Inserting a swf file in a windows application | face_master | Windows Programming | 12 | 05-03-2009 11:29 AM |
| can't get this program to run correctly | Amyaayaa | C++ Programming | 3 | 02-05-2008 04:16 PM |
| Merge and Heap..which is really faster | silicon | C++ Programming | 2 | 05-10-2005 04:06 PM |
| Program in linux to do LOTS of math (takes long time to complete) | Leeman_s | Linux Programming | 3 | 03-21-2004 06:02 PM |
| What's the code for a program to run in Task manager, under the processes tab | newbie1 | Windows Programming | 5 | 04-17-2003 07:07 AM |