diff options
| author | Martin Sustrik <sustrik@250bpm.com> | 2012-04-17 10:48:59 +0200 | 
|---|---|---|
| committer | Martin Sustrik <sustrik@250bpm.com> | 2012-04-18 07:16:00 +0200 | 
| commit | 464e0d5ed87f5e0c7fa10d13075e62307eba075f (patch) | |
| tree | 8105f2b380dacc9d7d6407f4b04851a1598d8976 | |
| parent | 3dc909eabddd68ff1b332af1e42978b55a3c17b6 (diff) | |
Improve efficiency of time measurement in tight loops
This patch instantiate a clock_t instance for each XS
socket. Thus, it is shared between subsequent calls
to xs_recv (and xs_send). That in turn significantly
limits the number of invocations of  getimeofday (or similar)
when timeouts are used and recv/send is called in a
tight loop.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
| -rw-r--r-- | src/socket_base.cpp | 3 | ||||
| -rw-r--r-- | src/socket_base.hpp | 4 | 
2 files changed, 4 insertions, 3 deletions
| diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 1f45fd6..39881d5 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -42,7 +42,6 @@  #include "io_thread.hpp"  #include "session_base.hpp"  #include "config.hpp" -#include "clock.hpp"  #include "pipe.hpp"  #include "err.hpp"  #include "ctx.hpp" @@ -558,7 +557,6 @@ int xs::socket_base_t::send (msg_t *msg_, int flags_)      //  Compute the time when the timeout should occur.      //  If the timeout is infite, don't care.  -    clock_t clock ;      uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout);      //  Oops, we couldn't send the message. Wait for the next @@ -643,7 +641,6 @@ int xs::socket_base_t::recv (msg_t *msg_, int flags_)      //  Compute the time when the timeout should occur.      //  If the timeout is infite, don't care.  -    clock_t clock ;      uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout);      //  In blocking scenario, commands are processed over and over again until diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 9225ce7..0f7dca8 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -32,6 +32,7 @@  #include "atomic_counter.hpp"  #include "mailbox.hpp"  #include "stdint.hpp" +#include "clock.hpp"  #include "pipe.hpp"  namespace xs @@ -202,6 +203,9 @@ namespace xs          //  True if the last message received had MORE flag set.          bool rcvmore; +        //  Improves efficiency of time measurement. +        clock_t clock; +          socket_base_t (const socket_base_t&);          const socket_base_t &operator = (const socket_base_t&);      }; | 
