hi.. can anybody please tell me that how can i print the execution time for my code ? Actually, what exaclty i want is that my program should also print the time which is elapsed while executing it or for maupulating any i/p. any pre-defined or user-defind function which can help, then please tell me. thanks. any help will be apprecited. thanks.
I_m_rude
Recommended Answers
Jump to PostYou could use the clock() function in the time.h header. The 0 value has nothing to do with real world time (it can be based on the time the program started, but is implementation specific). It gives you the number of clock cycles (ticks) that have ellapsed, so you have …
Jump to PostOh, why not:
int i; clock_t ticks; ticks = clock(); for(i = 0; i < 100000000; i++); ticks = clock() - ticks; printf("Number of ticks: %ld\n", ticks); printf("Clocks per second: %ld\n", CLOCKS_PER_SEC); printf("Time ellapsed: %ld ms\n", ticks * 1000 / CLOCKS_PER_SEC)); getchar();
Note, I did this …
Jump to PostI'm not sure what you mean by i/p... but if you want to not include a certain amount of time while something else is happening you could try this:
clock_t ticks; clock_t ticks_temp; ticks = clock(); ... ticks_temp = clock(); ... /* don't time this */ ... …
All 10 Replies
nmaillet
97
Posting Whiz in Training
I_m_rude
nmaillet
97
Posting Whiz in Training
I_m_rude
nmaillet
97
Posting Whiz in Training
I_m_rude
nmaillet
97
Posting Whiz in Training
I_m_rude
nmaillet
97
Posting Whiz in Training
I_m_rude
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.