473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

i m a student oly.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include"time.h"
  3. int main()
  4. {
  5. clock_t start,end;
  6. double value;
  7. start=clock();
  8. /*
  9. my proj code
  10. */
  11. end=clock();
  12. value=(end-start)/(double)CLOCKS_PER_SEC;
  13. printf("the total time is %g",value);
  14. }
i have done this code in gcc linux i3 core..i got same output zero(0) oly always. could any one help me pls???
and give me correct code..i want to calculate total execution time of this code...pls help me to complete my proj..
Nov 12 '13 #1
5 1262
donbock
2,426 Expert 2GB
Your proj code runs much faster than the resolution of clock(). There are two ways to work around that limitation: either use a timing function that has higher resolution or slow down your proj code. The easiest approach is the second: run your proj code many times (1,000, 10,000, ... or 1,000,000 times) and divide the reported time by that repeat-count.
Nov 12 '13 #2
thank u sir..but i did not get,could you send me sample code.please.
Jan 20 '14 #3
donbock
2,426 Expert 2GB
Insert a loop that executes lines 8-10 (your proj code) many times. Modify line 12 to also divide by that number of iterations. Adjust the number of iterations until you get a reasonable answer.
Jan 20 '14 #4
Banfa
9,065 Expert Mod 8TB
Note that with code like this you are measuring from the time it started until the time it stopped. This means on a multitasking OS, like Linux or Windows, that you may also include the processing time of any other applications and processes that are also running at that time.

To reduce the effect of this you should shut down as many other applications as possible before running this, you should give the system time to reach an equilibrium, that is for example if as a result of shutting down lots of tasks the OS decides to change the swapfile size you should wait for that to finish. And you should run you measuring application several times and discard any results that appear to be spikes in the data set.
Jan 21 '14 #5
thanku!!i need one more help..i want to split entire process of my coding into each and every core of my system...is there any command available for that in openMP?
Jan 21 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Kirk Bevins | last post by:
Hello, new to posting, got a dilema in c++. I cant seem to create new instances of my student class. The idea is to make a database where the user inputs surnames and library card numbers etc. The...
6
by: laj | last post by:
HI, Excuse this new question, I am trying to impress my wife by putting a db together for her dance studio. I put a table with all students new and old with fields including name and address and...
2
by: sallyk07 | last post by:
Modify the Student class so that each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the...
4
by: Dave White | last post by:
Hello Everyone, I have created two tables to track my students' lessons. Each student is responsible for most, but not all. of the lessons. I've tried a junction table but I can't figure out...
11
by: xxbabysue123xx | last post by:
Heres the problem: Create a class Student with instance data name, studentNumber, class (where class is a String containing one of the following: “Freshman”, “Sophomore”, “Junior”, “Senior”. ...
3
by: Synapse | last post by:
hi everyone..im trying to create a student list program using linked list that will display all my info of students..but it seems theres a little prob. after i enter my first student the program will...
4
by: withu4ever | last post by:
I learned how to use struct when I try to write a program i face some misstakes which I cant correct This is the program: ------------------------------------------------------- ...
4
by: lafayettejohnson | last post by:
there are 3 files but the one iam having problems with is the student.cpp student.cpp #include <iostream> // for ostream << and istream >> #include <string> #include "student.h"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.