time measurement


 
Thread Tools Search this Thread
Top Forums Programming time measurement
# 1  
Old 03-02-2006
time measurement

I have a bottleneck in one of my applications...I have a loop that goes through a few thousand interations, but does quite a few things (digs info out of a database, sends the data to another application, etc...). I want to put in some debugging to determine what function calls are taking the most time to execute. I thought about marking times with the time() function, but that only gives a measurment in seconds. Are there any functions that can give more precise measurments (maybe milliseconds)?
# 2  
Old 03-03-2006
use clock()

that would return in microseconds precision,

Code:
#include <stdio.h>
# include<time.h>

int main()
{
  int i;
  clock_t time_start;
  clock_t time_end;
  time_start=clock();
  for(i=0; i<100000; i++);
  time_end=clock();
  fprintf(stderr, "DIFF: %ld microseconds\n", time_end - time_start);
  return 0;
}
~

# 3  
Old 03-03-2006
Thanks! I think that will do it.
# 4  
Old 03-05-2006
clock() has a problem depending on the implementation. The granularity of the result is only guaranteed to be per second by the C99 standard. It can be finer. You can certainly try it.

gettimeofday returns the timeval struct which does have better resolution guranteed.

Do you know about cc -g -p myfile.c - o myfile ? profiling
You can then run your code, then look at the profiling output. gprof or prof will do this for you. It gives total times and number of calls for each function.
# 5  
Old 03-06-2006
i accept the point with respect to the granularity of the clock command
(time resolution is only .01 second )
but it is ANSI standard and it is easily portable

on the other, gettimeofday() applicable to SVr4 and BSD4.3 standards,
so most likely it should support other versions.
and one main drawback is lesser OS donot support it...
# 6  
Old 03-06-2006
Use GNU tools like gprof/gcov to analyse ur program.

John Arackal
# 7  
Old 03-07-2006
Quote:
I have a bottleneck in one of my applications...I have a loop that goes through a few thousand interations
You might want to sleep() at the end of each iteration to lower a bit cpu load and observer if the bottleneck is still there ...
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Redhat - IO performance measurement

Hi Currently we have SAN setup in our Redhat Environment. I have used iostat tool and ran it couple of times, i think there is IO bottle neck. Can anyone suggest any other tools or help me how to perform multiple Reads/Writes to test its performance (1 Reply)
Discussion started by: rakeshkumar
1 Replies

2. IP Networking

OID for Bandwith and Throughput Measurement

Hey Guys, Does anybody know, which OID's of Net-SNMP is used to collect throughput and bandwith usage of machine?? I got these OID's ..iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifOutOctets ..1.3.6.1.2.1.2.2.1.16 ... (1 Reply)
Discussion started by: franzramadhan
1 Replies

3. Shell Programming and Scripting

Measurement file parsing

I have an application performance measurement file with one thousand lines. Each line has some text indicating type of measurement and the last field containing the measured value. Each of the file has a unique measurement. I am interested in only extracting about 100 of those measurements and put... (2 Replies)
Discussion started by: yoda9691
2 Replies

4. IP Networking

SNMP OID for Network Utilization measurement

Hi everyone, I've just copied a snmpget script from somewhere. This script is basically used to collect basic router information. Ex: syscontact,syslocation,etc. And I want to extend the script to be able to collect some network information and utilization of some machines ex: bandwith usage,... (0 Replies)
Discussion started by: franzramadhan
0 Replies

5. Shell Programming and Scripting

convert file storage size from one unit of measurement to another

The source number is always in megabytes and I need a script to covert into either MB,GB or TB displayed in a specific format. Source number examples: 5345376635 34255 5453645846353 The result has to be maximum 2 numbers after the comma 1.13 TB 134.17 TB 413.46 GB 678.45 MB I... (3 Replies)
Discussion started by: TehOne
3 Replies

6. UNIX for Dummies Questions & Answers

Commands performance measurement

Hi, Actually i wanted to check out the process time for the execution of commands on unix, i looking for the script which can include all commands which are to be executed on the system and i need to get the time for executing each command, can somebody help me Thanks & Regards Murali (1 Reply)
Discussion started by: hsmuralidhara
1 Replies

7. UNIX for Advanced & Expert Users

Performance measurement of Code

I hope I am posting the query at right place.. I have the project running as 32 bit application on Solaris 8. I want to port this to 64Bit application. Before I start this process, I would like to compare the performance of a sample code running as 32Bit/64 Bit executables on a 64 bit... (1 Reply)
Discussion started by: amit_sapre
1 Replies
Login or Register to Ask a Question