Skip to content

Commit 5652a16

Browse files
committed
Update the Readme with fmt to the high performance example.
1 parent 54d1f5a commit 5652a16

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,33 +378,36 @@ int main() {
378378
}
379379
```
380380

381-
## You also can also use some additional options (currently only configure by macroses):
381+
## You also can use some additional options to maximize performance and reduce size (made by HedgehogInTheCPP):
382382

383383
There is a really common use case in mathematical and other abstract syntax tree (AST)-like parsers that already processes
384384
the sign and all other symbols before any number by itself. In this case you can use FastFloat to only parse positive numbers
385385
in all supported formats with macros `FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN`, which significantly reduce the code size
386-
and improve performance. An additional option for high performance and very fast processing is
387-
`FASTFLOAT_TABLE_HACK_CHAR_DIGIT_LUT_DISABLED`; it reduces data size and speeds up parsing because a data cache is used for your
388-
real data, not for a 256-byte table that flushes out at least 3 cache lines on x86. You also can use macros
389-
`FASTFLOAT_ISNOT_CHECKED_BOUNDS` if your code already checks bounds; it's very likely because all parsers need to check the first
390-
character by itself before parsing. Additionally, you can use macros `FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED` if you only need
391-
`FE_TONEAREST` rounding mode in the parsing; this option also improves performance a bit and reduces code size.
386+
and improve performance. You also can use macros `FASTFLOAT_ISNOT_CHECKED_BOUNDS` if your code already checks bounds;
387+
it's very likely because all parsers need to check the first character by itself before parsing. Additionally, you can use
388+
macros `FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED` if you only need `FE_TONEAREST` rounding mode in the parsing; this option
389+
also improves performance a bit and reduces code size. In the high-performance example, I also use the [fmt library](https://github.com/fmtlib/fmt), which also
390+
supports all C++ standards since C++11. I also recommend using `string_view` everywhere if it's possible; it's available
391+
since C++17, and if you want maximum performance, use the latest compiler with the latest C++ with O3 optimization and LTO!
392392
```C++
393393
#define FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
394-
#define FASTFLOAT_TABLE_HACK_CHAR_DIGIT_LUT_DISABLED
395394
#define FASTFLOAT_ISNOT_CHECKED_BOUNDS
396395
#define FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED
397396
#include "fast_float/fast_float.h"
398-
#include <iostream>
397+
#include "fmt/base.h"
398+
#include <string_view>
399399

400400
int main() {
401-
std::string input = "23.14069263277926900572";
401+
std::string_view input = "23.14069263277926900572";
402402
double result;
403403
auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result);
404404
if ((answer.ec != std::errc()) || ((result != 23.14069263277927 /*properly rounded value */)))
405-
{ std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
406-
407-
return EXIT_SUCCESS;
405+
{
406+
fmt::print(stderr, "parsing failure!\n the number {}.", result);
407+
return 1;
408+
}
409+
fmt::print("parsed the number {}.", result);
410+
return 0;
408411
}
409412
```
410413

0 commit comments

Comments
 (0)