various cast type performance

Timings retrieved on Pentium4 3.2Ghz

g++ version: 4.3.2-1

flags: -O3 -march=pentium4

boost: 1.34

 

  int to int int to double string to int string to double int to string double to string string to string

static_cast

1.3ns 0.9ns - - - - 179ns
c functions - - atoi
62ns
atof
142ns
sprintf**
383ns

sprinf**
2360ns

229ns**
stringstream 4163ns* 4592ns* 4194ns 4930ns 4052ns 6186ns 4196ns*
sprint::smart_cast
1.1ns
2.5ns
124ns
222ns
215ns
1037ns
244ns
boost::lexical_cast 2763ns 3045ns 2637ns 3357ns 2773ns 4897ns 2725ns

* only for reference. Only a fool can used stringstream in those cases!
** take care: sprintf can have buffer overrun fault

see Benchmark Cast Boost 1.33

see Recents Benchmark Cast Boost

see: http://accu.org/index.php/journals/1375

see: [Tuning] Alexander Nasonov, Fine Tuning for lexical_cast, Overload #74, August 2006

see: The String Formatters of Manor Farm