I want to calculate the time elapsed in receiving a message at client side. Here is what i am trying to do :
assuming buffer size for receiving is 500 bytes
1) Send a packet (say 500 bytes) from client to Server.
2) Server receives the packet and sends it back to the client.
3) Client Receives the packet back.'
(Note that i am not concerned with how many steps server takes to send message back, that is not in our control since i am using TCP protocol)
So far I have tried following things.
1) time() function it basically gives time in seconds, so I have to discard it because here execution time should be in milliseconds, and I was always getting 0 seconds with this.
2)clock() function, it tells us the no. of cycles it takes for execution and then if u divide it by CLOCKS_PER_SEC, you can get the time elapsed, but in my scenario it was not working, always giving 0 seconds.
3) gettimeofday(&tv , NULL) : I used this and am getting time in microseconds, but my problem is , it is giving me weird results i.e sometimes I get 500 usec, sometimes 1000 usec, sometimes 5000 usec and sometimes 10000 usec also. I can' t trust so much of variations .
There is nothing much in code, it is just a client-server socket prg code implementing TCP protocol with loopback port.(127.0.0.1).
I hope I made myself clear in defining my problem , I want some good function, which can tell me the time elapsed in what i am trying to do.
thanks in advance