Skip to content

Commit

Permalink
Merge branch 'fmtlib:master' into zig-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 10, 2024
2 parents 53cb64f + 7259929 commit 3431e10
Show file tree
Hide file tree
Showing 30 changed files with 3,349 additions and 3,269 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "MSDOS")
message(STATUS "MSDOS is incompatible with gtest")
endif ()

# Get version from core.h
file(READ include/fmt/core.h core_h)
# Get version from base.h
file(READ include/fmt/base.h core_h)
if (NOT core_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])")
message(FATAL_ERROR "Cannot get FMT_VERSION from core.h.")
message(FATAL_ERROR "Cannot get FMT_VERSION from base.h.")
endif ()
# Use math to skip leading zeros if any.
math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
Expand Down Expand Up @@ -274,7 +274,7 @@ function(add_headers VAR)
endfunction()

# Define the fmt library, its includes and the needed defines.
add_headers(FMT_HEADERS args.h chrono.h color.h compile.h core.h format.h
add_headers(FMT_HEADERS args.h chrono.h color.h compile.h base.h format.h
format-inl.h os.h ostream.h printf.h ranges.h std.h
xchar.h)
set(FMT_SOURCES src/format.cc)
Expand Down
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ that help victims of the war in Ukraine: <https://www.stopputin.net/>.
Q&A: ask questions on [StackOverflow with the tag
fmt](https://stackoverflow.com/questions/tagged/fmt).

Try {fmt} in [Compiler Explorer](https://godbolt.org/z/Eq5763).
Try {fmt} in [Compiler Explorer](https://godbolt.org/z/8Mx1EW73v).

# Features

Expand Down Expand Up @@ -203,43 +203,39 @@ and [ryu](https://github.com/ulfjack/ryu):

## Compile time and code bloat

The script
[bloat-test.py](https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py)
from [format-benchmark](https://github.com/fmtlib/format-benchmark)
tests compile time and code bloat for nontrivial projects. It generates
100 translation units and uses `printf()` or its alternative five times
in each to simulate a medium-sized project. The resulting executable
size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42), macOS
Sierra, best of three) is shown in the following tables.
The script [bloat-test.py][test] from [format-benchmark][bench] tests compile
time and code bloat for nontrivial projects. It generates 100 translation units
and uses `printf()` or its alternative five times in each to simulate a
medium-sized project. The resulting executable size and compile time (Apple
clang version 15.0.0 (clang-1500.1.0.2.5), macOS Sonoma, best of three) is shown
in the following tables.

[test]: https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py
[bench]: https://github.com/fmtlib/format-benchmark

**Optimized build (-O3)**

| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
|---------------|-----------------|----------------------|--------------------|
| printf | 2.6 | 29 | 26 |
| printf+string | 16.4 | 29 | 26 |
| iostreams | 31.1 | 59 | 55 |
| {fmt} | 19.0 | 37 | 34 |
| Boost Format | 91.9 | 226 | 203 |
| Folly Format | 115.7 | 101 | 88 |

As you can see, {fmt} has 60% less overhead in terms of resulting binary
code size compared to iostreams and comes pretty close to `printf`.
Boost Format and Folly Format have the largest overheads.
| printf | 1.6 | 54 | 50 |
| IOStreams | 25.6 | 98 | 84 |
| {fmt} 1b7d9db | 4.8 | 54 | 50 |
| tinyformat | 30.5 | 161 | 136 |
| Boost Format | 56.7 | 530 | 317 |

`printf+string` is the same as `printf` but with an extra `<string>`
include to measure the overhead of the latter.
As you can see, {fmt} has ~70% less overhead in terms of resulting binary code
size compared to iostreams and comes pretty close to `printf`. Boost Format and
Folly Format have the largest overheads.

**Non-optimized build**

| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
|---------------|-----------------|----------------------|--------------------|
| printf | 2.2 | 33 | 30 |
| printf+string | 16.0 | 33 | 30 |
| iostreams | 28.3 | 56 | 52 |
| {fmt} | 18.2 | 59 | 50 |
| Boost Format | 54.1 | 365 | 303 |
| Folly Format | 79.9 | 445 | 430 |
| printf | 1.4 | 54 | 50 |
| IOStreams | 24.2 | 92 | 68 |
| {fmt} 1b7d9db | 4.7 | 217 | 214 |
| tinyformat | 25.7 | 204 | 161 |
| Boost Format | 37.5 | 831 | 462 |

`libc`, `lib(std)c++`, and `libfmt` are all linked as shared libraries
to compare formatting function overhead only. Boost Format is a
Expand Down
9 changes: 7 additions & 2 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,16 @@ Standard Library Types Formatting

``fmt/std.h`` provides formatters for:

* `std::atomic <https://en.cppreference.com/w/cpp/atomic/atomic>`_
* `std::atomic_flag <https://en.cppreference.com/w/cpp/atomic/atomic_flag>`_
* `std::bitset <https://en.cppreference.com/w/cpp/utility/bitset>`_
* `std::error_code <https://en.cppreference.com/w/cpp/error/error_code>`_
* `std::filesystem::path <https://en.cppreference.com/w/cpp/filesystem/path>`_
* `std::thread::id <https://en.cppreference.com/w/cpp/thread/thread/id>`_
* `std::monostate <https://en.cppreference.com/w/cpp/utility/variant/monostate>`_
* `std::variant <https://en.cppreference.com/w/cpp/utility/variant/variant>`_
* `std::optional <https://en.cppreference.com/w/cpp/utility/optional>`_
* `std::source_location <https://en.cppreference.com/w/cpp/utility/source_location>`_
* `std::thread::id <https://en.cppreference.com/w/cpp/thread/thread/id>`_
* `std::variant <https://en.cppreference.com/w/cpp/utility/variant/variant>`_

Formatting Variants
-------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def build_docs(version='dev', **kwargs):
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
INPUT = {0}/args.h {0}/chrono.h {0}/color.h {0}/core.h \
INPUT = {0}/args.h {0}/core.h {0}/chrono.h {0}/color.h \
{0}/compile.h {0}/format.h {0}/os.h {0}/ostream.h \
{0}/printf.h {0}/ranges.h {0}/xchar.h
QUIET = YES
Expand Down
Loading

0 comments on commit 3431e10

Please sign in to comment.