Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added time_val::now_diff_{u,m}sec()

  • Loading branch information...
commit 932fa489168534657ae9975443cf548939c21caf 1 parent 0c58314
@saleyn authored
View
13 include/utxx/running_stat.hpp
@@ -168,10 +168,15 @@ struct basic_moving_average
#else
assert(!N || (N & (N-1)) == 0);
#endif
- assert((N && !a_capacity) || (!N && a_capacity));
- assert(!a_capacity || (a_capacity & (a_capacity-1)) == 0);
- if (a_capacity)
- m_data = new T[a_capacity];
+ if (!(N ^ a_capacity))
+ throw std::logic_error
+ ("utxx::basic_moving_average: both static and dynamic capacity is given");
+ if (a_capacity) {
+ if ((a_capacity & (a_capacity-1)) != 0)
+ throw std::invalid_argument
+ ("utxx::basic_moving_average: dynamic capacity must be power of 2");
+ m_data = new T[a_capacity];
+ }
clear();
}
View
20 include/utxx/time_val.hpp
@@ -157,6 +157,18 @@ namespace utxx {
return (double)tv.sec() + (double)tv.usec() / N10e6;
}
+ int64_t diff_usec(const time_val& t) const {
+ time_val tv(this->timeval());
+ tv -= t;
+ return (int64_t)tv.sec() * N10e6 + tv.usec();
+ }
+
+ int64_t diff_msec(const time_val& t) const {
+ time_val tv(this->timeval());
+ tv -= t;
+ return (int64_t)tv.sec() * 1000 + tv.usec() / 1000;
+ }
+
void add(long _sec, long _us) {
m_tv.tv_sec += _sec; m_tv.tv_usec += _us;
if (_sec || _us) normalize();
@@ -227,6 +239,14 @@ namespace utxx {
time_val tv; tv.now(); tv -= start;
return (double)tv.sec() + (double)tv.usec() / N10e6;
}
+ static int64_t now_diff_usec(const time_val& start) {
+ time_val tv; tv.now(); tv -= start;
+ return (int64_t)tv.sec() * N10e6 + tv.usec();
+ }
+ static int64_t now_diff_msec(const time_val& start) {
+ time_val tv; tv.now(); tv -= start;
+ return (int64_t)tv.sec() * 1000 + tv.usec() / 1000;
+ }
time_val operator- (const time_val& tv) const {
return time_val(m_tv.tv_sec - tv.sec(), m_tv.tv_usec - tv.usec());
View
2  test/test_time_val.cpp
@@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE( test_time_val )
BOOST_REQUIRE_EQUAL(4003, rel.usec());
BOOST_REQUIRE_EQUAL(4, rel.msec());
BOOST_REQUIRE_EQUAL(2004, rel.milliseconds());
- BOOST_REQUIRE_EQUAL(2004003, rel.microseconds());
+ BOOST_REQUIRE_EQUAL(2004003u, rel.microseconds());
BOOST_REQUIRE_EQUAL(2.004003, rel.seconds());
time_val add = now + rel;
Please sign in to comment.
Something went wrong with that request. Please try again.