optimize Time::Get methods

This commit is contained in:
Mathieu Lacage
2007-02-02 19:40:03 +01:00
parent 48ae43c61e
commit 2e4ee67fea
2 changed files with 9 additions and 11 deletions

View File

@@ -110,7 +110,7 @@ public:
* \return the ns3::HighPrecision object which holds the value
* stored in this Time<N> type.
*/
HighPrecision GetHighPrecision (void) const;
HighPrecision const &GetHighPrecision (void) const;
HighPrecision *PeekHighPrecision (void);
private:
@@ -138,7 +138,7 @@ TimeUnit<N>::TimeUnit (HighPrecision data)
{}
template <int N>
HighPrecision
HighPrecision const &
TimeUnit<N>::GetHighPrecision (void) const
{
return m_data;

View File

@@ -36,23 +36,21 @@ Time::Time (HighPrecision const& value)
double
Time::GetSeconds (void) const
{
HighPrecision seconds = GetHighPrecision ();
seconds.Div (HighPrecision (1000000000, false));
return seconds.GetDouble ();
double ns = GetHighPrecision ().GetDouble ();
return ns/1000000000.0;
}
int32_t
Time::GetMilliSeconds (void) const
{
HighPrecision ms = GetHighPrecision ();
ms.Div (HighPrecision (1000000, false));
return (int32_t) ms.GetInteger ();
int64_t ns = GetHighPrecision ().GetInteger ();
ns /= 1000000;
return ns;
}
int64_t
Time::GetMicroSeconds (void) const
{
HighPrecision us = GetHighPrecision ();
us.Div (HighPrecision (1000, false));
return us.GetInteger ();
int64_t ns = GetHighPrecision ().GetInteger ();
return ns/1000;
}
int64_t
Time::GetNanoSeconds (void) const