Index: libcxx/benchmarks/CMakeLists.txt =================================================================== --- libcxx/benchmarks/CMakeLists.txt +++ libcxx/benchmarks/CMakeLists.txt @@ -192,6 +192,7 @@ std_format_spec_string_unicode.bench.cpp string.bench.cpp stringstream.bench.cpp + system_error.bench.cpp to_chars.bench.cpp unordered_set_operations.bench.cpp util_smartptr.bench.cpp Index: libcxx/benchmarks/system_error.bench.cpp =================================================================== --- /dev/null +++ libcxx/benchmarks/system_error.bench.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "benchmark/benchmark.h" + +static void BM_SystemErrorWithMessage(benchmark::State& state) { + for (auto _ : state) { + std::error_code ec{}; + benchmark::DoNotOptimize(std::system_error{ec, ""}); + } +} +BENCHMARK(BM_SystemErrorWithMessage); + +static void BM_SystemErrorWithoutMessage(benchmark::State& state) { + for (auto _ : state) { + std::error_code ec{}; + benchmark::DoNotOptimize(std::system_error{ec}); + } +} +BENCHMARK(BM_SystemErrorWithoutMessage); + +BENCHMARK_MAIN(); Index: libcxx/src/system_error.cpp =================================================================== --- libcxx/src/system_error.cpp +++ libcxx/src/system_error.cpp @@ -127,6 +127,13 @@ return string(error_message); } #endif + +string make_error_str(const error_code& ec) { + if (ec) { + return ec.message(); + } + return string(); +} } // end namespace #endif @@ -256,7 +263,7 @@ } system_error::system_error(error_code ec) - : runtime_error(__init(ec, "")), + : runtime_error(make_error_str(ec)), __ec_(ec) { } @@ -274,7 +281,7 @@ } system_error::system_error(int ev, const error_category& ecat) - : runtime_error(__init(error_code(ev, ecat), "")), + : runtime_error(make_error_str(error_code(ev, ecat))), __ec_(error_code(ev, ecat)) { }