Bug 1870

Summary: AsInt function is useless (and slow)
Product: ns-3 Reporter: Tommaso Pecorella <tommaso.pecorella>
Component: networkAssignee: ns-bugs <ns-bugs>
Status: RESOLVED FIXED    
Severity: enhancement CC: takai.kenn
Priority: P5    
Version: ns-3-dev   
Hardware: All   
OS: All   
Attachments: Patch to remove AsInt

Description Tommaso Pecorella 2014-03-02 17:56:31 UTC
Created attachment 1791 [details]
Patch to remove AsInt

static uint8_t
AsInt (std::string v)
{
  NS_LOG_FUNCTION (v);
  std::istringstream iss;
  iss.str (v);
  uint32_t retval;
  iss >> std::hex >> retval >> std::dec;
  return retval;
}

is functionally equivalent to:
strtoul (tmp.c_str(), 0, 16)

The difference is the speed. AsInt is 20x time *slower*. See:
http://tinodidriksen.com/2010/02/16/cpp-convert-string-to-int-speed/

We're lucky that the stream extraction operator (where AsInt is called) isn't used often...
Comment 1 Tommaso Pecorella 2014-03-08 11:51:08 UTC
Pushed in changeset:   10647:0fd17d2704cd
Comment 2 Tommaso Pecorella 2014-03-14 17:51:45 UTC
*** Bug 1881 has been marked as a duplicate of this bug. ***