Bug 1870 - AsInt function is useless (and slow)
AsInt function is useless (and slow)
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: network
ns-3-dev
All All
: P5 enhancement
Assigned To: ns-bugs
:
: 1881 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-03-02 17:56 UTC by Tommaso Pecorella
Modified: 2014-03-14 17:51 UTC (History)
1 user (show)

See Also:


Attachments
Patch to remove AsInt (4.85 KB, application/octet-stream)
2014-03-02 17:56 UTC, Tommaso Pecorella
Details

Note You need to log in before you can comment on or make changes to this bug.
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. ***