Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Performance

Tests description
GNU C++ version 6.1.1 20160511
GNU C++ version 4.8.5
Clang version 3.6.0 (tags/RELEASE_360/final)

In most cases boost::lexical_cast is faster than scanf, printf, std::stringstream. For more detailed info you can look at the tables below.

All the tests measure execution speed in milliseconds for 10000 iterations of the following code blocks:

Table 19.1. Tests source code

Test name

Code

lexical_cast

_out = boost::lexical_cast<OUTTYPE>(_in);

std::stringstream with construction

std::stringstream ss;
ss << _in;
if (ss.fail()) throw std::logic_error(descr);
ss >> _out;
if (ss.fail()) throw std::logic_error(descr);

std::stringstream without construction

ss << _in; // ss is an instance of std::stringstream
if (ss.fail()) throw std::logic_error(descr);
ss >> _out;
if (ss.fail()) throw std::logic_error(descr);
/* reseting std::stringstream to use it again */
ss.str(std::string());
ss.clear();

scanf/printf

typename OUTTYPE::value_type buffer[500];
sprintf( (char*)buffer, conv, _in);
_out = buffer;


Fastest results are highlitened with "!!! x !!!". Do not use this results to compare compilers, because tests were taken on different hardware.

Table 19.2. Performance Table ( GNU C++ version 6.1.1 20160511)

From->To

lexical_cast

std::stringstream with construction

std::stringstream without construction

scanf/printf

string->char

!!! <1 !!!

59

4

4

string->signed char

!!! <1 !!!

52

4

5

string->unsigned char

!!! <1 !!!

54

4

5

string->int

!!! 4 !!!

61

19

12

string->short

!!! 4 !!!

59

11

8

string->long int

!!! 4 !!!

59

9

8

string->long long

!!! 6 !!!

61

10

10

string->unsigned int

!!! 4 !!!

59

9

9

string->unsigned short

!!! 4 !!!

60

9

8

string->unsigned long int

!!! 4 !!!

60

9

8

string->unsigned long long

!!! 4 !!!

70

21

21

string->float

91

152

59

!!! 40 !!!

string->double

86

140

58

!!! 28 !!!

string->long double

48

90

34

!!! 22 !!!

string->array<char, 50>

!!! <1 !!!

59

9

10

string->string

!!! 2 !!!

129

29

---

string->container::string

!!! 1 !!!

70

11

---

string->char

!!! 4 !!!

99

27

20

string->signed char

!!! 9 !!!

101

13

12

string->unsigned char

!!! 4 !!!

86

27

27

int->string

!!! 9 !!!

89

17

14

short->string

!!! 7 !!!

71

17

15

long int->string

!!! 7 !!!

71

18

19

long long->string

!!! 13 !!!

127

34

25

unsigned int->string

16

117

17

!!! 12 !!!

unsigned short->string

!!! 8 !!!

71

16

12

unsigned long int->string

!!! 12 !!!

100

36

26

unsigned long long->string

!!! 14 !!!

97

21

17

float->string

70

97

43

!!! 25 !!!

double->string

130

155

51

!!! 25 !!!

long double->string

104

160

!!! 47 !!!

57

char*->char

!!! <1 !!!

95

4

4

char*->signed char

!!! <1 !!!

52

7

13

char*->unsigned char

!!! <1 !!!

106

11

13

char*->int

!!! 6 !!!

118

22

21

char*->short

!!! 7 !!!

104

10

19

char*->long int

!!! 8 !!!

112

24

14

char*->long long

!!! 4 !!!

90

17

9

char*->unsigned int

!!! 4 !!!

103

23

22

char*->unsigned short

!!! 7 !!!

82

9

8

char*->unsigned long int

!!! 5 !!!

58

20

8

char*->unsigned long long

!!! 4 !!!

60

10

11

char*->float

58

103

!!! 32 !!!

37

char*->double

52

155

32

!!! 27 !!!

char*->long double

72

135

51

!!! 30 !!!

char*->array<char, 50>

!!! <1 !!!

80

23

17

char*->string

!!! 10 !!!

150

18

---

char*->container::string

!!! <1 !!!

64

11

---

unsigned char*->char

!!! <1 !!!

52

4

4

unsigned char*->signed char

!!! <1 !!!

54

4

5

unsigned char*->unsigned char

!!! <1 !!!

54

4

5

unsigned char*->int

!!! 4 !!!

59

10

8

unsigned char*->short

!!! 4 !!!

59

10

8

unsigned char*->long int

!!! 4 !!!

66

24

19

unsigned char*->long long

!!! 4 !!!

59

10

8

unsigned char*->unsigned int

!!! 4 !!!

79

24

22

unsigned char*->unsigned short

!!! 7 !!!

123

23

22

unsigned char*->unsigned long int

!!! 8 !!!

121

24

22

unsigned char*->unsigned long long

!!! 8 !!!

121

24

22

unsigned char*->float

97

167

67

!!! 47 !!!

unsigned char*->double

96

164

67

!!! 47 !!!

unsigned char*->long double

97

165

66

!!! 47 !!!

unsigned char*->array<char, 50>

!!! <1 !!!

119

22

17

unsigned char*->string

!!! 11 !!!

139

34

---

unsigned char*->container::string

!!! 1 !!!

121

25

---

signed char*->char

!!! <1 !!!

106

11

8

signed char*->signed char

!!! <1 !!!

81

12

13

signed char*->unsigned char

!!! <1 !!!

109

11

12

signed char*->int

!!! 7 !!!

122

24

21

signed char*->short

!!! 4 !!!

59

10

8

signed char*->long int

!!! 4 !!!

60

10

8

signed char*->long long

!!! 4 !!!

60

10

8

signed char*->unsigned int

!!! 4 !!!

64

23

22

signed char*->unsigned short

!!! 7 !!!

120

24

22

signed char*->unsigned long int

!!! 8 !!!

121

24

22

signed char*->unsigned long long

!!! 8 !!!

122

23

22

signed char*->float

95

165

68

!!! 46 !!!

signed char*->double

95

161

66

!!! 47 !!!

signed char*->long double

96

161

66

!!! 46 !!!

signed char*->array<char, 50>

!!! <1 !!!

117

22

17

signed char*->string

!!! 10 !!!

84

15

---

signed char*->container::string

!!! 1 !!!

119

25

---

iterator_range<char*>->char

!!! <1 !!!

111

16

11

iterator_range<char*>->signed char

!!! <1 !!!

110

16

13

iterator_range<char*>->unsigned char

!!! <1 !!!

111

15

13

iterator_range<char*>->int

!!! 6 !!!

119

25

22

iterator_range<char*>->short

!!! 7 !!!

119

25

22

iterator_range<char*>->long int

!!! 7 !!!

120

25

22

iterator_range<char*>->long long

!!! 8 !!!

119

24

22

iterator_range<char*>->unsigned int

!!! 6 !!!

119

24

22

iterator_range<char*>->unsigned short

!!! 6 !!!

117

24

22

iterator_range<char*>->unsigned long int

!!! 7 !!!

120

24

22

iterator_range<char*>->unsigned long long

!!! 8 !!!

118

24

22

iterator_range<char*>->float

96

155

48

!!! 47 !!!

iterator_range<char*>->double

96

141

47

!!! 47 !!!

iterator_range<char*>->long double

96

140

46

!!! 46 !!!

iterator_range<char*>->array<char, 50>

!!! <1 !!!

118

25

17

iterator_range<char*>->string

!!! 10 !!!

136

35

---

iterator_range<char*>->container::string

!!! 1 !!!

119

26

---

array<char, 50>->char

!!! <1 !!!

108

11

10

array<char, 50>->signed char

!!! <1 !!!

106

12

12

array<char, 50>->unsigned char

!!! <1 !!!

107

11

13

array<char, 50>->int

!!! 6 !!!

119

24

22

array<char, 50>->short

!!! 7 !!!

121

24

22

array<char, 50>->long int

!!! 7 !!!

119

24

22

array<char, 50>->long long

!!! 7 !!!

123

24

22

array<char, 50>->unsigned int

!!! 7 !!!

121

23

25

array<char, 50>->unsigned short

!!! 6 !!!

120

24

22

array<char, 50>->unsigned long int

!!! 7 !!!

59

10

9

array<char, 50>->unsigned long long

!!! 4 !!!

60

10

8

array<char, 50>->float

47

80

32

!!! 22 !!!

array<char, 50>->double

46

82

31

!!! 22 !!!

array<char, 50>->long double

49

82

31

!!! 22 !!!

array<char, 50>->array<char, 50>

!!! 1 !!!

59

9

7

array<char, 50>->string

!!! 5 !!!

70

15

---

array<char, 50>->container::string

!!! 1 !!!

60

11

---

int->int

!!! <1 !!!

61

12

---

float->double

!!! <1 !!!

111

54

---

char->signed char

!!! <1 !!!

51

4

---


Table 19.3. Performance Table ( GNU C++ version 4.8.5)

From->To

lexical_cast

std::stringstream with construction

std::stringstream without construction

scanf/printf

string->char

!!! <1 !!!

100

10

10

string->signed char

!!! <1 !!!

97

9

11

string->unsigned char

!!! <1 !!!

103

11

13

string->int

!!! 6 !!!

122

23

22

string->short

!!! 6 !!!

116

23

22

string->long int

!!! 6 !!!

97

21

22

string->long long

!!! 7 !!!

118

22

22

string->unsigned int

!!! 6 !!!

116

22

22

string->unsigned short

!!! 6 !!!

106

9

8

string->unsigned long int

!!! 3 !!!

59

9

8

string->unsigned long long

!!! 3 !!!

58

9

8

string->float

88

166

70

!!! 47 !!!

string->double

102

162

65

!!! 51 !!!

string->long double

96

163

71

!!! 46 !!!

string->array<char, 50>

!!! 1 !!!

112

21

18

string->string

!!! 2 !!!

139

37

---

string->container::string

!!! 1 !!!

121

24

---

string->char

!!! 9 !!!

121

31

21

string->signed char

!!! 9 !!!

121

31

34

string->unsigned char

!!! 9 !!!

120

31

30

int->string

!!! 17 !!!

141

39

30

short->string

!!! 18 !!!

142

39

30

long int->string

17

136

17

!!! 12 !!!

long long->string

!!! 7 !!!

69

17

13

unsigned int->string

!!! 8 !!!

70

24

13

unsigned short->string

!!! 7 !!!

69

17

12

unsigned long int->string

!!! 7 !!!

71

16

12

unsigned long long->string

!!! 7 !!!

71

16

12

float->string

60

95

49

!!! 24 !!!

double->string

68

97

45

!!! 26 !!!

long double->string

72

108

45

!!! 28 !!!

char*->char

!!! <1 !!!

52

5

4

char*->signed char

!!! <1 !!!

52

5

5

char*->unsigned char

!!! <1 !!!

52

5

5

char*->int

!!! 3 !!!

60

10

8

char*->short

!!! 3 !!!

61

10

8

char*->long int

!!! 4 !!!

60

10

8

char*->long long

!!! 4 !!!

61

9

8

char*->unsigned int

!!! 3 !!!

103

13

8

char*->unsigned short

!!! 3 !!!

97

23

22

char*->unsigned long int

!!! 7 !!!

123

23

22

char*->unsigned long long

!!! 6 !!!

72

10

8

char*->float

85

160

66

!!! 47 !!!

char*->double

94

161

65

!!! 46 !!!

char*->long double

94

172

64

!!! 47 !!!

char*->array<char, 50>

!!! 2 !!!

113

22

16

char*->string

!!! 10 !!!

145

34

---

char*->container::string

!!! 1 !!!

120

25

---

unsigned char*->char

!!! <1 !!!

102

11

10

unsigned char*->signed char

!!! <1 !!!

100

12

12

unsigned char*->unsigned char

!!! <1 !!!

102

11

12

unsigned char*->int

!!! 7 !!!

119

24

22

unsigned char*->short

!!! 7 !!!

120

24

22

unsigned char*->long int

!!! 7 !!!

119

24

23

unsigned char*->long long

!!! 7 !!!

119

24

22

unsigned char*->unsigned int

!!! 6 !!!

82

9

8

unsigned char*->unsigned short

!!! 3 !!!

58

9

8

unsigned char*->unsigned long int

!!! 4 !!!

59

10

10

unsigned char*->unsigned long long

!!! 4 !!!

60

12

8

unsigned char*->float

47

80

32

!!! 22 !!!

unsigned char*->double

47

79

31

!!! 23 !!!

unsigned char*->long double

47

80

31

!!! 22 !!!

unsigned char*->array<char, 50>

!!! 1 !!!

58

9

7

unsigned char*->string

!!! 4 !!!

68

15

---

unsigned char*->container::string

!!! <1 !!!

60

10

---

signed char*->char

!!! <1 !!!

52

5

4

signed char*->signed char

!!! <1 !!!

54

4

5

signed char*->unsigned char

!!! <1 !!!

52

4

6

signed char*->int

!!! 6 !!!

59

10

8

signed char*->short

!!! 3 !!!

59

10

8

signed char*->long int

!!! 4 !!!

60

10

8

signed char*->long long

!!! 4 !!!

59

10

9

signed char*->unsigned int

!!! 3 !!!

58

9

8

signed char*->unsigned short

!!! 4 !!!

58

9

8

signed char*->unsigned long int

!!! 4 !!!

59

10

8

signed char*->unsigned long long

!!! 4 !!!

59

10

8

signed char*->float

47

81

32

!!! 25 !!!

signed char*->double

46

79

31

!!! 22 !!!

signed char*->long double

48

80

32

!!! 22 !!!

signed char*->array<char, 50>

!!! 1 !!!

63

9

7

signed char*->string

!!! 4 !!!

68

15

---

signed char*->container::string

!!! <1 !!!

58

10

---

iterator_range<char*>->char

!!! <1 !!!

54

6

4

iterator_range<char*>->signed char

!!! <1 !!!

57

6

5

iterator_range<char*>->unsigned char

!!! <1 !!!

54

6

5

iterator_range<char*>->int

!!! 3 !!!

59

10

8

iterator_range<char*>->short

!!! 3 !!!

59

11

9

iterator_range<char*>->long int

!!! 3 !!!

61

11

8

iterator_range<char*>->long long

!!! 3 !!!

59

10

9

iterator_range<char*>->unsigned int

!!! 3 !!!

57

9

8

iterator_range<char*>->unsigned short

!!! 3 !!!

59

10

8

iterator_range<char*>->unsigned long int

!!! 3 !!!

58

10

8

iterator_range<char*>->unsigned long long

!!! 3 !!!

58

15

8

iterator_range<char*>->float

46

78

22

!!! 22 !!!

iterator_range<char*>->double

94

85

!!! 21 !!!

22

iterator_range<char*>->long double

47

79

33

!!! 22 !!!

iterator_range<char*>->array<char, 50>

!!! 1 !!!

102

25

16

iterator_range<char*>->string

!!! 10 !!!

96

16

---

iterator_range<char*>->container::string

!!! <1 !!!

64

11

---

array<char, 50>->char

!!! <1 !!!

75

4

4

array<char, 50>->signed char

!!! <1 !!!

54

6

13

array<char, 50>->unsigned char

!!! <1 !!!

103

12

12

array<char, 50>->int

!!! 6 !!!

121

25

23

array<char, 50>->short

!!! 7 !!!

122

24

22

array<char, 50>->long int

!!! 7 !!!

119

24

22

array<char, 50>->long long

!!! 7 !!!

120

24

22

array<char, 50>->unsigned int

!!! 6 !!!

121

23

22

array<char, 50>->unsigned short

!!! 6 !!!

121

23

22

array<char, 50>->unsigned long int

!!! 6 !!!

118

24

20

array<char, 50>->unsigned long long

!!! 6 !!!

109

22

21

array<char, 50>->float

93

150

61

!!! 43 !!!

array<char, 50>->double

89

147

61

!!! 43 !!!

array<char, 50>->long double

91

148

61

!!! 42 !!!

array<char, 50>->array<char, 50>

!!! 2 !!!

106

21

15

array<char, 50>->string

!!! 10 !!!

124

32

---

array<char, 50>->container::string

!!! 1 !!!

109

23

---

int->int

!!! <1 !!!

114

26

---

float->double

!!! <1 !!!

207

105

---

char->signed char

!!! <1 !!!

97

10

---


Table 19.4. Performance Table ( Clang version 3.6.0 (tags/RELEASE_360/final))

From->To

lexical_cast

std::stringstream with construction

std::stringstream without construction

scanf/printf

string->char

!!! <1 !!!

79

4

4

string->signed char

!!! <1 !!!

51

4

5

string->unsigned char

!!! <1 !!!

51

4

5

string->int

!!! 3 !!!

80

22

22

string->short

!!! 6 !!!

108

22

22

string->long int

!!! 6 !!!

66

10

11

string->long long

!!! 6 !!!

101

9

20

string->unsigned int

!!! 5 !!!

77

8

8

string->unsigned short

!!! 3 !!!

61

8

8

string->unsigned long int

!!! 5 !!!

87

9

9

string->unsigned long long

!!! 3 !!!

89

9

8

string->float

52

114

38

!!! 22 !!!

string->double

49

79

32

!!! 22 !!!

string->long double

83

160

65

!!! 47 !!!

string->array<char, 50>

!!! <1 !!!

114

21

16

string->string

!!! 2 !!!

78

34

---

string->container::string

!!! 1 !!!

100

11

---

string->char

!!! 4 !!!

60

16

7

string->signed char

!!! 5 !!!

70

30

30

string->unsigned char

!!! 10 !!!

119

31

30

int->string

!!! 17 !!!

140

38

28

short->string

!!! 17 !!!

139

38

29

long int->string

!!! 17 !!!

139

37

29

long long->string

!!! 18 !!!

138

37

30

unsigned int->string

!!! 17 !!!

138

37

29

unsigned short->string

!!! 17 !!!

139

38

29

unsigned long int->string

!!! 17 !!!

142

37

29

unsigned long long->string

!!! 8 !!!

71

16

28

float->string

68

97

42

!!! 38 !!!

double->string

68

134

43

!!! 25 !!!

long double->string

72

164

91

!!! 55 !!!

char*->char

!!! <1 !!!

76

4

5

char*->signed char

!!! <1 !!!

54

5

5

char*->unsigned char

!!! <1 !!!

55

4

5

char*->int

!!! 3 !!!

60

10

8

char*->short

!!! 3 !!!

61

9

8

char*->long int

!!! 4 !!!

61

9

8

char*->long long

!!! 3 !!!

60

9

8

char*->unsigned int

!!! 3 !!!

59

8

9

char*->unsigned short

!!! 3 !!!

59

10

8

char*->unsigned long int

!!! 3 !!!

59

10

8

char*->unsigned long long

!!! 3 !!!

59

10

8

char*->float

48

80

32

!!! 25 !!!

char*->double

48

81

32

!!! 22 !!!

char*->long double

48

90

31

!!! 22 !!!

char*->array<char, 50>

!!! <1 !!!

59

9

7

char*->string

!!! 4 !!!

77

15

---

char*->container::string

!!! 1 !!!

62

12

---

unsigned char*->char

!!! <1 !!!

54

4

5

unsigned char*->signed char

!!! <1 !!!

53

4

5

unsigned char*->unsigned char

!!! <1 !!!

57

4

5

unsigned char*->int

!!! 3 !!!

63

24

24

unsigned char*->short

!!! 5 !!!

65

9

9

unsigned char*->long int

!!! 3 !!!

60

10

8

unsigned char*->long long

!!! 4 !!!

67

23

23

unsigned char*->unsigned int

!!! 5 !!!

116

23

22

unsigned char*->unsigned short

!!! 5 !!!

114

22

22

unsigned char*->unsigned long int

!!! 6 !!!

118

23

22

unsigned char*->unsigned long long

!!! 6 !!!

116

23

22

unsigned char*->float

93

160

66

!!! 47 !!!

unsigned char*->double

93

158

64

!!! 46 !!!

unsigned char*->long double

93

158

64

!!! 46 !!!

unsigned char*->array<char, 50>

!!! <1 !!!

112

21

17

unsigned char*->string

!!! 10 !!!

136

33

---

unsigned char*->container::string

!!! <1 !!!

117

26

---

signed char*->char

!!! <1 !!!

102

11

10

signed char*->signed char

!!! <1 !!!

102

11

12

signed char*->unsigned char

!!! <1 !!!

102

11

12

signed char*->int

!!! 5 !!!

119

23

22

signed char*->short

!!! 5 !!!

116

23

22

signed char*->long int

!!! 6 !!!

116

23

22

signed char*->long long

!!! 6 !!!

115

23

22

signed char*->unsigned int

!!! 5 !!!

116

23

22

signed char*->unsigned short

!!! 5 !!!

114

22

22

signed char*->unsigned long int

!!! 6 !!!

92

9

8

signed char*->unsigned long long

!!! 3 !!!

60

9

10

signed char*->float

94

134

51

!!! 28 !!!

signed char*->double

47

80

31

!!! 22 !!!

signed char*->long double

90

115

64

!!! 25 !!!

signed char*->array<char, 50>

!!! <1 !!!

97

22

17

signed char*->string

!!! 11 !!!

139

34

---

signed char*->container::string

!!! <1 !!!

118

26

---

iterator_range<char*>->char

!!! <1 !!!

106

15

10

iterator_range<char*>->signed char

!!! <1 !!!

107

15

13

iterator_range<char*>->unsigned char

!!! <1 !!!

107

15

12

iterator_range<char*>->int

!!! 5 !!!

117

25

22

iterator_range<char*>->short

!!! 5 !!!

116

25

22

iterator_range<char*>->long int

!!! 6 !!!

114

22

20

iterator_range<char*>->long long

!!! 5 !!!

106

23

22

iterator_range<char*>->unsigned int

!!! 5 !!!

104

21

20

iterator_range<char*>->unsigned short

!!! 5 !!!

105

22

20

iterator_range<char*>->unsigned long int

!!! 5 !!!

106

22

20

iterator_range<char*>->unsigned long long

!!! 5 !!!

105

23

20

iterator_range<char*>->float

89

140

!!! 42 !!!

43

iterator_range<char*>->double

88

127

43

!!! 43 !!!

iterator_range<char*>->long double

88

127

43

!!! 43 !!!

iterator_range<char*>->array<char, 50>

!!! <1 !!!

104

22

15

iterator_range<char*>->string

!!! 9 !!!

122

32

---

iterator_range<char*>->container::string

!!! <1 !!!

105

24

---

array<char, 50>->char

!!! <1 !!!

68

4

4

array<char, 50>->signed char

!!! <1 !!!

47

4

5

array<char, 50>->unsigned char

!!! <1 !!!

48

4

5

array<char, 50>->int

!!! 3 !!!

53

9

8

array<char, 50>->short

!!! 3 !!!

54

9

8

array<char, 50>->long int

!!! 3 !!!

54

8

7

array<char, 50>->long long

!!! 3 !!!

53

8

8

array<char, 50>->unsigned int

!!! 3 !!!

52

7

8

array<char, 50>->unsigned short

!!! 3 !!!

53

8

7

array<char, 50>->unsigned long int

!!! 3 !!!

53

8

8

array<char, 50>->unsigned long long

!!! 3 !!!

53

9

8

array<char, 50>->float

43

72

29

!!! 20 !!!

array<char, 50>->double

42

72

28

!!! 20 !!!

array<char, 50>->long double

43

72

28

!!! 20 !!!

array<char, 50>->array<char, 50>

!!! <1 !!!

53

8

6

array<char, 50>->string

!!! 4 !!!

62

13

---

array<char, 50>->container::string

!!! 1 !!!

54

10

---

int->int

!!! <1 !!!

57

10

---

float->double

!!! <1 !!!

102

49

---

char->signed char

!!! <1 !!!

49

3

---



PrevUpHomeNext