diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 9a4f54c..2620e2c 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,4 +1,5 @@ -We have benchmarks, please consider running them: see our README for details. +We have benchmarks, please consider running them: [see our README for details](https://github.com/fastfloat/fast_float/blob/main/README.md#benchmarking). We expect you to run our benchmarks if you make claims with respect to the performance. + Our CI tests check formatting automating. If such a test fails, please consider running the bash script: diff --git a/.github/workflows/vs17-ci.yml b/.github/workflows/vs17-ci.yml index 3b59805..0fe0bbd 100644 --- a/.github/workflows/vs17-ci.yml +++ b/.github/workflows/vs17-ci.yml @@ -19,7 +19,7 @@ jobs: uses: actions/checkout@v4 - name: configure run: | - cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -DFASTFLOAT_TEST=ON -DCMAKE_INSTALL_PREFIX:PATH=destination + cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -DFASTFLOAT_BENCHMARKS=ON -DFASTFLOAT_TEST=ON -DCMAKE_INSTALL_PREFIX:PATH=destination - name: build run: | cmake --build build --verbose --config ${{matrix.cfg}} --parallel diff --git a/.github/workflows/vs17-clang-ci.yml b/.github/workflows/vs17-clang-ci.yml index 20c1dea..f7e6ba8 100644 --- a/.github/workflows/vs17-clang-ci.yml +++ b/.github/workflows/vs17-clang-ci.yml @@ -19,7 +19,7 @@ jobs: uses: actions/checkout@v4 - name: Configure run: | - cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -T ClangCL -DFASTFLOAT_TEST=ON + cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -DFASTFLOAT_BENCHMARKS=ON -T ClangCL -DFASTFLOAT_TEST=ON - name: Build run: cmake --build build --config ${{matrix.cfg}} --parallel --verbose - name: Run basic tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 08b417a..8a1c9a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.9) -project(fast_float VERSION 8.0.0 LANGUAGES CXX) +project(fast_float VERSION 8.0.2 LANGUAGES CXX) set(FASTFLOAT_CXX_STANDARD 11 CACHE STRING "the C++ standard to use for fastfloat") set(CMAKE_CXX_STANDARD ${FASTFLOAT_CXX_STANDARD}) option(FASTFLOAT_TEST "Enable tests" OFF) @@ -55,11 +55,15 @@ if(FASTFLOAT_SANITIZE) target_link_libraries(fast_float INTERFACE -fuse-ld=gold) endif() endif() -if(MSVC_VERSION GREATER 1910) + +include(CheckCXXCompilerFlag) +unset(FASTFLOAT_COMPILER_SUPPORTS_PERMISSIVE) +CHECK_CXX_COMPILER_FLAG(/permissive- FASTFLOAT_COMPILER_SUPPORTS_PERMISSIVE) + +if(FASTFLOAT_COMPILER_SUPPORTS_PERMISSIVE) target_compile_options(fast_float INTERFACE /permissive-) endif() - if(FASTFLOAT_INSTALL) include(CMakePackageConfigHelpers) diff --git a/README.md b/README.md index a67ede2..da92603 100644 --- a/README.md +++ b/README.md @@ -472,7 +472,7 @@ abseil : 430.45 MB/s (+/- 2.2 %) 20.52 Mfl fastfloat : 1042.38 MB/s (+/- 9.9 %) 49.68 Mfloat/s ``` -See the [Benchmarking](#benchmarking) Section for instructions on how to run our benchmarks. +See the [Benchmarking](#benchmarking) section for instructions on how to run our benchmarks. ## Video @@ -498,7 +498,7 @@ sufficiently recent version of CMake (3.11 or better at least): FetchContent_Declare( fast_float GIT_REPOSITORY https://github.com/fastfloat/fast_float.git - GIT_TAG tags/v8.0.0 + GIT_TAG tags/v8.0.2 GIT_SHALLOW TRUE) FetchContent_MakeAvailable(fast_float) @@ -514,7 +514,7 @@ You may also use [CPM](https://github.com/cpm-cmake/CPM.cmake), like so: CPMAddPackage( NAME fast_float GITHUB_REPOSITORY "fastfloat/fast_float" - GIT_TAG v8.0.0) + GIT_TAG v8.0.2) ``` ## Using as single header @@ -526,7 +526,7 @@ if desired as described in the command line help. You may directly download automatically generated single-header files: - + ## Benchmarking @@ -551,6 +551,14 @@ in some cases: sudo ./build/benchmarks/realbenchmark ``` +If you have a text file containing one number per line (`myfile.txt`), you can run a benchmark over it like so: +``` +cmake -B build -D FASTFLOAT_BENCHMARKS=ON +cmake --build build +./build/benchmarks/realbenchmark myfile.txt +``` + + ## Packages * The fast_float library is part of the [Conan package diff --git a/benchmarks/benchmark.cpp b/benchmarks/benchmark.cpp index 60009b0..54d96d9 100644 --- a/benchmarks/benchmark.cpp +++ b/benchmarks/benchmark.cpp @@ -282,7 +282,11 @@ int main(int argc, char **argv) { #endif } #endif - + if (argc > 1) { + fileload(argv[1]); + return EXIT_SUCCESS; + } fileload(std::string(BENCHMARK_DATA_DIR) + "/canada.txt"); fileload(std::string(BENCHMARK_DATA_DIR) + "/mesh.txt"); + return EXIT_SUCCESS; } diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 7c2f5fd..52c2963 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -289,7 +289,7 @@ report_parse_error(UC const *p, parse_error error) noexcept { // Assuming that you use no more than 19 digits, this will // parse an ASCII string. -template +template fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t parse_number_string(UC const *p, UC const *pend, parse_options_t const &options) noexcept { @@ -301,20 +301,20 @@ parse_number_string(UC const *p, UC const *pend, #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN answer.negative = (*p == UC('-')); // C++17 20.19.3.(7.1) explicitly forbids '+' sign here - if ((*p == UC('-')) || - (uint64_t(options.format & chars_format::allow_leading_plus) && - !uint64_t(options.format & detail::basic_json_fmt) && *p == UC('+'))) { + if ((*p == UC('-')) || (uint64_t(options.format & chars_format::allow_leading_plus) && + !basic_json_fmt && *p == UC('+'))) { ++p; if (p == pend) { return report_parse_error( p, parse_error::missing_integer_or_dot_after_sign); } - if (uint64_t(options.format & detail::basic_json_fmt)) { + FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) { if (!is_integer(*p)) { // a sign must be followed by an integer return report_parse_error(p, parse_error::missing_integer_after_sign); } - } else { + } + else { if (!is_integer(*p) && (*p != options.decimal_point)) { // a sign must be followed by an integer or the dot @@ -340,8 +340,7 @@ parse_number_string(UC const *p, UC const *pend, UC const *const end_of_integer_part = p; int64_t digit_count = int64_t(end_of_integer_part - start_digits); answer.integer = span(start_digits, size_t(digit_count)); -#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN - if (uint64_t(options.format & detail::basic_json_fmt)) { + FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) { // at least 1 digit in integer part, without leading zeros if (digit_count == 0) { return report_parse_error(p, parse_error::no_digits_in_integer_part); @@ -351,7 +350,6 @@ parse_number_string(UC const *p, UC const *pend, parse_error::leading_zeros_in_integer_part); } } -#endif int64_t exponent = 0; bool const has_decimal_point = (p != pend) && (*p == options.decimal_point); @@ -371,17 +369,14 @@ parse_number_string(UC const *p, UC const *pend, answer.fraction = span(before, size_t(p - before)); digit_count -= exponent; } -#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN - if (uint64_t(options.format & detail::basic_json_fmt)) { + FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) { // at least 1 digit in fractional part if (has_decimal_point && exponent == 0) { return report_parse_error(p, parse_error::no_digits_in_fractional_part); } - } else -#endif - if (digit_count == - 0) { // we must have encountered at least one integer! + } + else if (digit_count == 0) { // we must have encountered at least one integer! return report_parse_error(p, parse_error::no_digits_in_mantissa); } int64_t exp_number = 0; // explicit exponential part diff --git a/include/fast_float/constexpr_feature_detect.h b/include/fast_float/constexpr_feature_detect.h index ca245ed..e29b586 100644 --- a/include/fast_float/constexpr_feature_detect.h +++ b/include/fast_float/constexpr_feature_detect.h @@ -31,6 +31,11 @@ #define FASTFLOAT_HAS_BYTESWAP 1 #else #define FASTFLOAT_HAS_BYTESWAP 0 + +#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L +#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x) +#else +#define FASTFLOAT_IF_CONSTEXPR17(x) if (x) #endif // Testing for relevant C++20 constexpr library features diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 28d8671..3f1c8fc 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -17,7 +17,7 @@ #define FASTFLOAT_VERSION_MAJOR 8 #define FASTFLOAT_VERSION_MINOR 0 -#define FASTFLOAT_VERSION_PATCH 0 +#define FASTFLOAT_VERSION_PATCH 2 #define FASTFLOAT_STRINGIZE_IMPL(x) #x #define FASTFLOAT_STRINGIZE(x) FASTFLOAT_STRINGIZE_IMPL(x) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 80eb364..2b427f8 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -324,7 +324,12 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, FASTFLOAT_ASSUME(first < last); #endif parsed_number_string_t const pns = - parse_number_string(first, last, options); +#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN + uint64_t(fmt & detail::basic_json_fmt) + ? parse_number_string(first, last, options) + : +#endif + parse_number_string(first, last, options); if (!pns.valid) { #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN if (uint64_t(options.format & chars_format::no_infnan)) { diff --git a/tests/json_fmt.cpp b/tests/json_fmt.cpp index f04207a..1ba0d5a 100644 --- a/tests/json_fmt.cpp +++ b/tests/json_fmt.cpp @@ -131,7 +131,7 @@ int main() { for (std::size_t i = 0; i < reject.size(); ++i) { auto const &f = reject[i].input; auto const &expected_reason = reject[i].reason; - auto answer = fast_float::parse_number_string( + auto answer = fast_float::parse_number_string( f.data(), f.data() + f.size(), fast_float::parse_options( fast_float::chars_format::json |