answersLogoWhite

0


Best Answer

This is a big question... but I'll try for a shortish answer. Try to do things in approximately the following order.

1) Use the right algorithms. Look into the Big O efficiency of any algorithms you are using, and make sure there aren't more efficient algorithms available.

2) Think about trading using more memory for a faster algorithm. Perhaps pre-computing tables of intermediate results.

3) Use a profiler to see where the bottle necks are and try improving them.

4) Optimize the inner most loops using assembly language to get the last little bit faster.

5) Run it on a faster computer.

6) Make it run in parallel across many computers or CPUs. This is especially good on the newer Intel chips where you have access to multiple CPUs on one chip. Distributed network computing sometimes is a good idea. Cloud computing is another possibility these days.

7) Make sure that C really is the right answer. It might not be in all cases.

A more specific question might yield a more specific answer.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Calculating running times are OS-dependent. In Linux, use clock_getres() and clock_gettime(). In Windows, use QueryPerformanceFrequency() and QueryPerformanceCounter().

To perform a timing, you need to determine the frequency of the high performance event timer (HPET). This never changes while a machine is running, so it only needs to be done once (usually when your program loads) with a call to clock_getres() or QueryPerformanceFrequency(). Store the value -- you will need it later.

To time a process, you need to store the current HPET counter value, both before and after calling the process you want to time, by calling clock_gettime() or QueryPerformanceCounter().

To calculate the elapsed time, use the following formula:

(( end_count - start_count ) * multiplier) / frequency

All values must be unsigned long long (64-bit), with the exception of the multiplier, which must be a long double. The return value should also be long double.

The multiplier determines the resolution, as per the following:

1.0 = seconds (s)

1,000.0 = milliseconds (ms)

1,000,000.0 = microseconds (us)

1,000,000,000.0 = nanoseconds (ns)

In order to perform nanosecond timing, you need an HPET with a frequency of at least 100MHz (1 tick per 1ns). A 25MHz HPET resolves to only 1 tick per 40ns. Keep in mind that your CPU is measured in GHz, so short processes can easily be completed in well under 40ns and would be impossible to time with a 25MHz HPET.

Note that the call to clock_gettime() or QueryPerformanceCounter() constitutes an overhead (a minimum of 25 ticks on my system, which is 1 microsecond at 25MHz). So any process that takes a minimum of 25 ticks to complete would be impossible to time.

However, in performance timing, shaving 1 nanosecond off a process isn't going to make a huge difference when you consider that a burst of background activity can easily skew timings by as much as 1 microsecond (1,000ns).

HPET is supported by Windows Vista, Windows Server 2008, Linux 2.6 kernel, Mac OS X, FreeBSD and OpenSolaris. Windows XP support is emulated in SP3. See the related link for further information.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

that's what command time is good for. Try it:

time sleep 3

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

In unix it is time, example:

$ time ls -l

...

real 0m0.008s

user 0m0.000s

sys 0m0.004s

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you calculate the c program running time through c plus plus coding?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is program memory?

Program memory refers to a type of memory used in coding. This memory is where the coding originally comes from.


Write a program for Hoffman coding?

Yes.


How does a computer know that a program is not register?

Programs run with a step by step coding line. For example, when you open your program, a piece of coding will see if you have registered or not. If you have, it will go to step 2, if not, it will either disable some futures, close program or always ask to register. There are only 2 ways to bypass it: 1. Register it 2. Delete the line coding within the program coding.


What is the coding of program which can simplify mathematical expression in c?

34.768


The Medicare program uses a system of coding composed of two levels and this is called what?

Healthcare Common Procedure Coding System (HCPCS)


Does the actual coding of a program is done by system analyst?

no! By software engineer


Can you mix both c and assembly coding in one program?

yes......


Can you obtain a billing and coding license from online courses?

Depending on the number of online medical billing classes and medical coding classes you take per quarter, the certificate program can be completed within one year. At the same time, the program can prepare you to sit for the certification exams after successful completion of Parts II of any of the billing and coding courses. As a result, you can achieve national certification even before completing Drexels Medical Billing and Coding Certificate Program. Moreover, since the tuition for the program is based on the number of credits taken and not on the entire program, you are under no obligation to complete every medical billing and coding class.


What kind of program is interpreters?

An interpreter is a specialized kind of computer program. This program executes instructions written in a programming language that is not the native coding.


What are billing and coding jobs used for?

Building and coding jobs are used for creating computer programs and mobile apps, to build a program or app you must first learn to code the app or program that you wish to build.


What makes Hunter College's medical billing and coding training unique?

After researching the website I do not see much difference in Hunter's College's billing and coding program from other colleges. Here is a overview of its program if you're interested: http://www.hunter.cuny.edu/ce/certificates/medical-coding-and-billing-certificate


What type of binary coding does Xusenet use?

Uuencode is the oldest code that xusenet uses to program it's binary coding and is considered a reliable source of coding by many of its many international computer users.