Thanks fo your valuable advice. This is the output I got, but I wonder how its working in linux very fastly [with in 20 sec and in HP 1.06 minutes]. Can you help me in finding the problem responsible for this.
$ prof cpp_sw_gsmconverter
%Time Seconds Cumsecs #Calls msec/call Name
It looks like you are trying to do random access on a file, because you're spending a lot of time repositioning the disk heads (__lseek_sys).
This is probably okay on desktop Linux boxes. This is a no-no on a multiuser system.
Here's why. Suppose you want to make 20 separate deposit transactions at the bank.
If you go to the teller and do all 20 at one time, it's fast. If you are limited to one transaction, and then you have to go to the back of the line and wait your turn again, it takes a LOT longer. Your code is in line and having to wait for everybody else's I/O requests to complete everytime you ask the disk to reposition the head. Plus you end up re-reading a lot more off disk (assuming a disk hardware cache) than exists in the file.
50% of your time is disk I/O. You're I/O bound. Big time.
Read the entire file sequentially into memory with one call. Put the file into an array of binary records, then access them using random methods. try something like this:
Thank you very much for your wonderful reply. Can you please explain me why file buffers[set with setvbuf() ] does not come to rescue when we issue seek command[ for 1 or 2 bytes forward or backward], that trys to fetch data which may be in buffer only. Can you provide links to valuable resources that helps in accomplishing a faster I/O in C. Once again thanks for your great reply.
The default value for BUFFSIZE is usually 4096, which is what the stdio C functions like fgets or fread read from. You should never set the value to a small number except for very special cases. If you have a copy of 'Advanced Programming in the UNIX Environment' look on pages 68-70 for I/O efficiency. BUFFSIZE of 4096 is really optimum.
Anytime the seek goes beyond the buffer boundary, you have to go back into kernel mode to get another buffer. Which means you get to wait. And because you're on a multi-user system, it's possible the hard drive cache has been flushed by somebody else. So you get to wait for I/O.
If you are really moving the file pointer ahead or back by 1-2 bytes, you REALLY should have read the whole file into memory. seek is not meant to do that thousands of times. It's like using ungetc which can cause the same problem. I would seriously consider a pointer instead. Here is a starter version, it compiles.
Again hats off to your wonderful reply. What I noticed now is subsequent calls to ftell() command is taking more time [40-50% of time] and when I simulated a file position counter , the c program is taking only 44 seconds. When sample programs were prepared with more file reads and file seeks in HP UX, its working quite fastly but including ftell() to get file position is slowing the program.
Profile of last c program when custom file position counter is implemented::
hi all,
can any one plz tell me that what is the difference between linux shell scripting and unix shell scripting.
is there any difference at all?? if yes that what are the differences and how could it be combatted
thanks in advance (1 Reply)
I wondered if someone could point out the differences between the time commmand and usr/bin/time and the accuracy one might have over another.
Also, is there a website or two a person could maybe link for me to describe the differences?
Thank you for your time. (2 Replies)
I am sure this question has been asked and answered before, also, if it is the wrong catergory, please let me know.
I would like to know how, if possible to run Unix/Linux as my operating system, and then load XP as a program? (I am open to other operating systems, but it has to be able to... (3 Replies)
Sorry if this is a stupid question!
I have been developing a Java application that I am deploying on both Unix and Linux servers, which uses lots of socket handling. When the server side connection is dropped by the server un-gracefully I have been seeing close_waits and null connections.
... (0 Replies)
:rolleyes: Hi,
How to take the time diffence between start and finish time from a log file?
It is like
..... started at Jun 20 23:20
.
.
..... finished at Jun 21 01:40
Tryed so many ways but failed to ger exact way. :confused:
Your help will be honoured.
Ta........Lokesha (1 Reply)
A thanks to all ahead of time.
I've checked previous posts about this subject and can't find any that quite fit what I need. If I've missed the post could you point me there.
When I do an ls -al I get the following output:
-rw-r--r-- 1 staff staff 855 July 24 20:05 ... (4 Replies)
Hi everyone,
I need to be able to write into a ksh script, a function that can look at 2 24 hour time variables and work out the difference between them.
e.g
job1 runs at 21:00
job2 runs at 01:00
diff = 04:00 hours
I would also need negative numbers i.e where job1 runs after job2
... (1 Reply)
Hello there,
I have the following mission for my internship:
- Take an existing program which uses OpenGL writen in Delphi, for Windows.
- Write this program in C++ for all operating systems from which the name end on a "X"
So, what kind of features does this program need.
- There... (1 Reply)