4646#endif
4747
4848void process (std::vector<double > &lines) {
49- size_t repeat = 100 ;
50- pretty_print (lines, " std::to_string" , [](std::vector<double > &lines) {
49+ pretty_print (lines, " std::to_string" , [](const std::vector<double > &lines) {
5150 double volume = 0 ;
52- for (auto d : lines) {
53- std::string s = std::to_string (d);
51+ for (const auto d : lines) {
52+ const std::string s = std::to_string (d);
5453 volume += s.size ();
5554 }
5655 return volume;
5756 });
58- pretty_print (lines, " fmt::format" , [](std::vector<double > &lines) {
57+ pretty_print (lines, " fmt::format" , [](const std::vector<double > &lines) {
5958 double volume = 0 ;
60- for (auto d : lines) {
61- std::string s = fmt::format (" {}" , d);
59+ for (const auto d : lines) {
60+ const std::string s = fmt::format (" {}" , d);
6261 volume += s.size ();
6362 }
6463 return volume;
6564 });
6665#if NETLIB_SUPPORTED
67- pretty_print (
68- lines, " netlib" ,
69- [](std::vector<double > &lines) {
70- double volume = 0 ;
71- char *result;
72- int decpt, sign;
73- char *rve;
74- for (auto d : lines) {
75- char *result = dtoa (d, 0 , 0 , &decpt, &sign, &rve);
76- if (result) {
77- volume += (rve - result);
78- freedtoa (result);
79- } else {
80- std::cerr << " problem with " << d << std::endl;
81- std::abort ();
82- }
83- }
84- return volume;
85- },
86- 10 );
66+ pretty_print (lines, " netlib" , [](const std::vector<double > &lines) {
67+ double volume = 0 ;
68+ char *result;
69+ int decpt, sign;
70+ char *rve;
71+ for (const auto d : lines) {
72+ char *result = dtoa (d, 0 , 0 , &decpt, &sign, &rve);
73+ if (result) {
74+ volume += (rve - result);
75+ freedtoa (result);
76+ } else {
77+ std::cerr << " problem with " << d << std::endl;
78+ std::abort ();
79+ }
80+ }
81+ return volume;
82+ }, 10 );
8783#else
8884 std::cout << " # netlib not supported" << std::endl;
8985#endif
90- pretty_print (lines, " sprintf" , [](std::vector<double > &lines) {
86+ pretty_print (lines, " sprintf" , [](const std::vector<double > &lines) {
9187 double volume = 0 ;
9288 char buffer[100 ];
93- for (auto d : lines) {
89+ for (const auto d : lines) {
9490 volume += snprintf (buffer, sizeof (buffer), " %g" , d);
9591 }
9692 return volume;
9793 });
98- pretty_print (lines, " grisu2" , [](std::vector<double > &lines) {
94+ pretty_print (lines, " grisu2" , [](const std::vector<double > &lines) {
9995 double volume = 0 ;
10096 char buffer[100 ];
101- for (auto d : lines) {
102- char *newp = grisu2::to_chars (buffer, nullptr , d);
97+ for (const auto d : lines) {
98+ const char *newp = grisu2::to_chars (buffer, nullptr , d);
10399 volume += newp - buffer;
104100 }
105101 return volume;
106102 });
107103#if FROM_CHARS_DOUBLE_SUPPORTED
108- pretty_print (lines, " std::to_chars" , [](std::vector<double > &lines) {
104+ pretty_print (lines, " std::to_chars" , [](const std::vector<double > &lines) {
109105 double volume = 0 ;
110106 char buffer[100 ];
111- for (auto d : lines) {
112- auto [p, ec] = std::to_chars (buffer, buffer + sizeof (buffer), d);
107+ for (const auto d : lines) {
108+ const auto [p, ec] = std::to_chars (buffer, buffer + sizeof (buffer), d);
113109 if (ec != std::errc ()) {
114110 std::cerr << " problem with " << d << std::endl;
115111 std::abort ();
@@ -121,26 +117,35 @@ void process(std::vector<double> &lines) {
121117#else
122118 std::cout << " # std::to_chars not supported" << std::endl;
123119#endif
124- pretty_print (lines, " dragonbox" , [](std::vector<double > &lines) {
120+ pretty_print (lines, " dragonbox" , [](const std::vector<double > &lines) {
125121 double volume = 0 ;
126122 char buffer[100 ];
127- for (auto d : lines) {
128- char *end_ptr = jkj::dragonbox::to_chars (d, buffer);
123+ for (const auto d : lines) {
124+ const char *end_ptr = jkj::dragonbox::to_chars (d, buffer);
129125 volume += end_ptr - &buffer[0 ];
130126 }
131127 return volume;
132128 });
133129
134- pretty_print (lines, " double_conversion" , [](std::vector<double > &lines) {
130+ pretty_print (lines, " ryu" , [](const std::vector<double > &lines) {
131+ double volume = 0 ;
132+ char buffer[100 ];
133+ for (const auto d : lines) {
134+ volume += d2s_buffered_n (d, buffer);
135+ }
136+ return volume;
137+ });
138+
139+ pretty_print (lines, " double_conversion" , [](const std::vector<double > &lines) {
135140 double volume = 0 ;
136- double_conversion::DoubleToStringConverter converter (
141+ const double_conversion::DoubleToStringConverter converter (
137142 double_conversion::DoubleToStringConverter::NO_FLAGS, " inf" , " nan" , ' e' ,
138143 -4 , 6 , 0 , 0 );
139144 const int kBufferSize = 100 ;
140145 char buffer[kBufferSize ];
141146 double_conversion::StringBuilder builder (buffer, kBufferSize );
142147
143- for (auto d : lines) {
148+ for (const auto d : lines) {
144149 builder.Reset ();
145150 if (!converter.ToShortest (d, &builder)) {
146151 std::cerr << " problem with " << d << std::endl;
@@ -151,10 +156,10 @@ void process(std::vector<double> &lines) {
151156 return volume;
152157 });
153158
154- pretty_print (lines, " abseil" , [](std::vector<double > &lines) {
159+ pretty_print (lines, " abseil" , [](const std::vector<double > &lines) {
155160 double volume = 0 ;
156161 std::string buffer;
157- for (auto d : lines) {
162+ for (const auto d : lines) {
158163 buffer.clear ();
159164 absl::StrAppend (&buffer, d);
160165 volume += buffer.size ();
0 commit comments