-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from mborland/benchmarks
Add benchmarks
- Loading branch information
Showing
11 changed files
with
1,333 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2023 Matt Borland | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <double-conversion/double-conversion.h> | ||
|
||
int main() | ||
{ | ||
using namespace double_conversion; | ||
|
||
const int flags = 0; | ||
int processed; | ||
|
||
auto converter = StringToDoubleConverter(flags, 0.0, 0.0, "inf", "nan"); | ||
|
||
auto result = converter.StringToDouble("0.0", 3, &processed); | ||
|
||
return static_cast<int>(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
//// | ||
Copyright 2023 Matt Borland | ||
Distributed under the Boost Software License, Version 1.0. | ||
https://www.boost.org/LICENSE_1_0.txt | ||
//// | ||
|
||
= Benchmarks | ||
:idprefix: benchmarks | ||
|
||
The values are relative to the performance of `std::printf` and `std::strtoX`. | ||
Larger numbers are more performant (e.g. 2.00 means twice as fast, and 0.50 means it takes twice as long). | ||
|
||
== How to run the Benchmarks | ||
|
||
To run the benchmarks yourself navigate to the test folder, and define `BOOST_CHARCONV_RUN_BENCHMARKS` when running the tests. | ||
An example on linux with b2: `../../../b2 cxxstd=20 toolset=gcc-13 define=BOOST_CHARCONV_RUN_BENCHMARKS STL_benchmark -a release` . | ||
|
||
Additionally, you will need the following: | ||
|
||
* A compiler with full `<charconv>` support: | ||
** GCC 11 or newer | ||
** MSVC 19.24 or newer | ||
* https://github.com/google/double-conversion[libdouble-conversion] | ||
|
||
== x86_64 Linux | ||
|
||
Data in tables 1 - 4 were run on Ubuntu 23.04 with x86_64 architecture using GCC 13.1.0 with libstdc++. | ||
|
||
=== Floating Point | ||
|
||
.to_chars floating point with the shortest representation | ||
|=== | ||
|Function|Relative Performance (float / double) | ||
|
||
|std::printf | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.55 / 0.46 | ||
|Boost.spirit.karma | ||
|1.80 / 2.62 | ||
|std::to_chars | ||
|3.53 / 4.87 | ||
|Boost.Charconv.to_chars | ||
|3.64 / 4.92 | ||
|Google double-conversion | ||
|1.19 / 1.85 | ||
|=== | ||
|
||
.from_chars floating point with scientific formatting | ||
|=== | ||
|Function|Relative Performance (float / double) | ||
|
||
|std::strto(f/d) | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.33 / 0.42 | ||
|Boost.spirit.qi | ||
|3.17 / 4.65 | ||
|std::from_chars | ||
|3.23 / 5.77 | ||
|Boost.Charconv.from_chars | ||
|3.28 / 5.75 | ||
|Google double-conversion | ||
|1.16 / 1.30 | ||
|=== | ||
|
||
=== Integral | ||
|
||
.to_chars base 10 integers | ||
|=== | ||
|Function|Relative Performance (uint32_t / uint64_t) | ||
|
||
|std::printf | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|1.77 / 1.41 | ||
|Boost.spirit.karma | ||
|2.55 / 1.47 | ||
|std::to_chars | ||
|3.86 / 2.25 | ||
|Boost.Charconv.to_chars | ||
|3.81 / 2.25 | ||
|=== | ||
|
||
.from_chars base 10 integers | ||
|=== | ||
|Function|Relative Performance (uint32_t / uint64_t) | ||
|
||
|std::strto(ul,ull) | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.53 / 0.52 | ||
|Boost.spirit.qi | ||
|2.24 / 1.49 | ||
|std::from_chars | ||
|1.97 / 1.68 | ||
|Boost.Charconv.from_chars | ||
|2.54 / 1.78 | ||
|=== | ||
|
||
== x86_64 Windows | ||
|
||
Data in tables 5 - 8 were run on Windows 11 with x86_64 architecture using MSVC 14.3 (V17.7.0). | ||
|
||
=== Floating Point | ||
|
||
.to_chars floating point with the shortest representation | ||
|=== | ||
|Function|Relative Performance (float / double) | ||
|
||
|std::printf | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.50 / 0.70 | ||
|Boost.spirit.karma | ||
|2.23 / 7.58 | ||
|std::to_chars | ||
|5.58 / 15.77 | ||
|Boost.Charconv.to_chars | ||
|5.62 / 15.26 | ||
|=== | ||
|
||
.from_chars floating point with scientific formatting | ||
|=== | ||
|Function|Relative Performance (float / double) | ||
|
||
|std::strto(f/d) | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.14 / 0.20 | ||
|Boost.spirit.qi | ||
|2.03 / 4.58 | ||
|std::from_chars | ||
|1.01 / 1.23 | ||
|Boost.Charconv.from_chars | ||
|2.06 / 5.21 | ||
|=== | ||
|
||
=== Integral | ||
|
||
.to_chars base 10 integers | ||
|=== | ||
|Function|Relative Performance (uint32_t / uint64_t) | ||
|
||
|std::printf | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.68 / 0.68 | ||
|Boost.spirit.karma | ||
|2.75 / 1.67 | ||
|std::to_chars | ||
|2.75 / 2.10 | ||
|Boost.Charconv.to_chars | ||
|2.75 / 2.06 | ||
|=== | ||
|
||
.from_chars base 10 integers | ||
|=== | ||
|Function|Relative Performance (uint32_t / uint64_t) | ||
|
||
|std::strto(ul,ull) | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.46 / 0.39 | ||
|Boost.spirit.qi | ||
|1.94 / 1.63 | ||
|std::from_chars | ||
|2.43 / 2.18 | ||
|Boost.Charconv.from_chars | ||
|2.68 / 2.27 | ||
|=== | ||
|
||
== ARM MacOS | ||
|
||
Data in tables 9-12 were run on MacOS Ventura 13.5 with M1 Pro architecture using Homebrew GCC 13.1.0 with libstdc++. | ||
|
||
=== Floating Point | ||
|
||
.to_chars floating point with the shortest representation | ||
|=== | ||
|Function|Relative Performance (float / double) | ||
|
||
|std::printf | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.52 / 0.12 | ||
|Boost.spirit.karma | ||
|1.40 / 1.40 | ||
|std::to_chars | ||
|3.01 / 2.96 | ||
|Boost.Charconv.to_chars | ||
|3.03 / 2.96 | ||
|Google double-conversion | ||
|1.22 / 1.16 | ||
|=== | ||
|
||
.from_chars floating point with scientific formatting | ||
|=== | ||
|Function|Relative Performance (float / double) | ||
|
||
|std::strto(f/d) | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.06 / 0.06 | ||
|Boost.spirit.qi | ||
|1.12 / 1.06 | ||
|std::from_chars | ||
|1.32 / 1.65 | ||
|Boost.Charconv.from_chars | ||
|1.28 / 1.63 | ||
|Google double-conversion | ||
|0.45 / 0.32 | ||
|
||
|=== | ||
|
||
=== Integral | ||
|
||
.to_chars base 10 integers | ||
|=== | ||
|Function|Relative Performance (uint32_t / uint64_t) | ||
|
||
|std::printf | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|2.08 / 1.75 | ||
|Boost.spirit.karma | ||
|4.17 / 2.06 | ||
|std::to_chars | ||
|6.25 / 4.12 | ||
|Boost.Charconv.to_chars | ||
|6.25 / 4.12 | ||
|=== | ||
|
||
.from_chars base 10 integers | ||
|=== | ||
|Function|Relative Performance (uint32_t / uint64_t) | ||
|
||
|std::strto(ul,ull) | ||
|1.00 / 1.00 | ||
|Boost.lexical_cast | ||
|0.56 / 0.54 | ||
|Boost.spirit.qi | ||
|1.39 / 1.33 | ||
|std::from_chars | ||
|1.92 / 1.65 | ||
|Boost.Charconv.from_chars | ||
|2.27 / 1.65 | ||
|=== | ||
|
||
Special thanks to Stephan T. Lavavej for providing the basis for the benchmarks. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.