Commit 7aacab8a by Abseil Team Committed by Mark Barolak

- e2f6b8ac647271815b4fed2991f405524dd762c3 Release cctz microbenchmarks. by…

  - e2f6b8ac647271815b4fed2991f405524dd762c3 Release cctz microbenchmarks. by Alex Strelnikov <strel@google.com>
  - 924ba2a3f9fca695d73c6bf491d20669e2b96b8e Changed RawPtr to use std::addressof() instead of operato... by Abseil Team <absl-team@google.com>
  - e8cf67f9fa74d4c5632da35547025ad2301c6819 Import of CCTZ from GitHub. by Alex Strelnikov <strel@google.com>
  - 2ece8a96611afcddd7b91e0197dadb896248250c Abandon ".inc" files in favor of ".h" headers. by Jorg Brown <jorg@google.com>
  - 37f5ed5da4058f90fb3e6a2733fce5b1fd0aaedf Add exception safety tests for absl::optional<T> by Abseil Team <absl-team@google.com>
  - 337f995a866b8f905f64ca6b271b5fec8f248a60 Update WORKSPACE to grab specific commits of dependencies... by Alex Strelnikov <strel@google.com>
  - 93e5b134607a554993387ad913e6c1621606004b Release Charmap microbenchmark. by Alex Strelnikov <strel@google.com>
  - 95c2e29b6d93ec1334484ee37d91f63101c45307 Release OStringStream microbenchmarks. by Alex Strelnikov <strel@google.com>
  - 250f51839ed26dd1e6b658d35aa291413e5f4825 Internal change by Greg Falcon <gfalcon@google.com>
  - ce34900fa3d1a95a8446bc943cdd801fac95be25 Improve compatibility of cctz cc_test targets for portabl... by Shaindel Schwartz <shaindel@google.com>
  - ce7e31dbf2c1ee93c79aae5b7dc7c603cb4babcf Improve portability of cc_tests. (Mark more tests that ca... by Abseil Team <absl-team@google.com>
  - dfcd4e455923703c1a1dcd523c5f915f7990fa2a Accept strings with custom allocators as arguments to abs... by Greg Falcon <gfalcon@google.com>
  - 2946b41ed3d5b8b5a8dc11182e443cf1ab6e3bde Link against benchmark_main instead of using BENCHMARK_MA... by Alex Strelnikov <strel@google.com>
  - f09de9e03bf8edd363069c4b352d8009423f531c Adds link to doc about the formats allowed by SimpleAtof(... by Greg Miller <jgm@google.com>
  - 59b0977e7a308e0800277886cf60226b2cc426a1 Simplify the HideMask() calculation so that it doesn't us... by Jorg Brown <jorg@google.com>

GitOrigin-RevId: e2f6b8ac647271815b4fed2991f405524dd762c3
Change-Id: Ib9c8547ed7fe217fad6cb3ab1362e96181aa5cfa
parent 99477fa9
...@@ -13,20 +13,20 @@ http_archive( ...@@ -13,20 +13,20 @@ http_archive(
# GoogleTest/GoogleMock framework. Used by most unit-tests. # GoogleTest/GoogleMock framework. Used by most unit-tests.
http_archive( http_archive(
name = "com_google_googletest", name = "com_google_googletest",
urls = ["https://github.com/google/googletest/archive/master.zip"], urls = ["https://github.com/google/googletest/archive/4e4df226fc197c0dda6e37f5c8c3845ca1e73a49.zip"],
strip_prefix = "googletest-master", strip_prefix = "googletest-4e4df226fc197c0dda6e37f5c8c3845ca1e73a49",
) )
# Google benchmark. # Google benchmark.
http_archive( http_archive(
name = "com_github_google_benchmark", name = "com_github_google_benchmark",
urls = ["https://github.com/google/benchmark/archive/master.zip"], urls = ["https://github.com/google/benchmark/archive/16703ff83c1ae6d53e5155df3bb3ab0bc96083be.zip"],
strip_prefix = "benchmark-master", strip_prefix = "benchmark-16703ff83c1ae6d53e5155df3bb3ab0bc96083be",
) )
# RE2 regular-expression framework. Used by some unit-tests. # RE2 regular-expression framework. Used by some unit-tests.
http_archive( http_archive(
name = "com_googlesource_code_re2", name = "com_googlesource_code_re2",
urls = ["https://github.com/google/re2/archive/master.zip"], urls = ["https://github.com/google/re2/archive/6cf8ccd82dbaab2668e9b13596c68183c9ecd13f.zip"],
strip_prefix = "re2-master", strip_prefix = "re2-6cf8ccd82dbaab2668e9b13596c68183c9ecd13f",
) )
...@@ -49,7 +49,7 @@ cc_test( ...@@ -49,7 +49,7 @@ cc_test(
deps = [ deps = [
":algorithm", ":algorithm",
"//absl/base:core_headers", "//absl/base:core_headers",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
......
...@@ -124,5 +124,3 @@ BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, EightBits) ...@@ -124,5 +124,3 @@ BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, EightBits)
->Range(kMinBenchmarkSize, kMaxBenchmarkSize); ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -392,11 +392,6 @@ cc_test( ...@@ -392,11 +392,6 @@ cc_test(
"//absl:windows": [], "//absl:windows": [],
"//conditions:default": ["-pthread"], "//conditions:default": ["-pthread"],
}), }),
tags = [
"no_test_android_arm",
"no_test_android_arm64",
"no_test_android_x86",
],
deps = [":malloc_internal"], deps = [":malloc_internal"],
) )
...@@ -426,6 +421,6 @@ cc_test( ...@@ -426,6 +421,6 @@ cc_test(
deps = [ deps = [
":base", ":base",
"//absl/synchronization", "//absl/synchronization",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -23,9 +23,7 @@ namespace base_internal { ...@@ -23,9 +23,7 @@ namespace base_internal {
// Arbitrary value with high bits set. Xor'ing with it is unlikely // Arbitrary value with high bits set. Xor'ing with it is unlikely
// to map one valid pointer to another valid pointer. // to map one valid pointer to another valid pointer.
constexpr uintptr_t HideMask() { constexpr uintptr_t HideMask() {
static_assert(sizeof(uintptr_t) == 4 || sizeof(uintptr_t) == 8, return (uintptr_t{0xF03A5F7BU} << (sizeof(uintptr_t) - 4) * 8) | 0xF03A5F7BU;
"uintptr_t must be 32 or 64 bits");
return sizeof(uintptr_t) == 8 ? 0xF03A5F7BF03A5F7BULL : 0xF03A5F7BUL;
} }
// Hide a pointer from the leak checker. For internal use only. // Hide a pointer from the leak checker. For internal use only.
......
...@@ -36,5 +36,3 @@ void BM_UnsafeCurrentThreadIdentity(benchmark::State& state) { ...@@ -36,5 +36,3 @@ void BM_UnsafeCurrentThreadIdentity(benchmark::State& state) {
BENCHMARK(BM_UnsafeCurrentThreadIdentity); BENCHMARK(BM_UnsafeCurrentThreadIdentity);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -42,11 +42,6 @@ cc_test( ...@@ -42,11 +42,6 @@ cc_test(
name = "fixed_array_test", name = "fixed_array_test",
srcs = ["fixed_array_test.cc"], srcs = ["fixed_array_test.cc"],
copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG,
tags = [
"no_test_android_arm",
"no_test_android_arm64",
"no_test_android_x86",
],
deps = [ deps = [
":fixed_array", ":fixed_array",
"//absl/base:exception_testing", "//absl/base:exception_testing",
...@@ -74,7 +69,7 @@ cc_test( ...@@ -74,7 +69,7 @@ cc_test(
tags = ["benchmark"], tags = ["benchmark"],
deps = [ deps = [
":fixed_array", ":fixed_array",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -131,7 +126,7 @@ cc_test( ...@@ -131,7 +126,7 @@ cc_test(
":inlined_vector", ":inlined_vector",
"//absl/base", "//absl/base",
"//absl/strings", "//absl/strings",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
......
...@@ -64,5 +64,3 @@ BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 256)->Range(0, 1 << 16); ...@@ -64,5 +64,3 @@ BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 256)->Range(0, 1 << 16);
BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 65536)->Range(0, 1 << 16); BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 65536)->Range(0, 1 << 16);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -372,5 +372,3 @@ void BM_StdVectorEmpty(benchmark::State& state) { ...@@ -372,5 +372,3 @@ void BM_StdVectorEmpty(benchmark::State& state) {
BENCHMARK(BM_StdVectorEmpty); BENCHMARK(BM_StdVectorEmpty);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -179,9 +179,9 @@ typename memory_internal::MakeUniqueResult<T>::invalid make_unique( ...@@ -179,9 +179,9 @@ typename memory_internal::MakeUniqueResult<T>::invalid make_unique(
// useful within templates that need to handle a complement of raw pointers, // useful within templates that need to handle a complement of raw pointers,
// `std::nullptr_t`, and smart pointers. // `std::nullptr_t`, and smart pointers.
template <typename T> template <typename T>
auto RawPtr(T&& ptr) -> decltype(&*ptr) { auto RawPtr(T&& ptr) -> decltype(std::addressof(*ptr)) {
// ptr is a forwarding reference to support Ts with non-const operators. // ptr is a forwarding reference to support Ts with non-const operators.
return (ptr != nullptr) ? &*ptr : nullptr; return (ptr != nullptr) ? std::addressof(*ptr) : nullptr;
} }
inline std::nullptr_t RawPtr(std::nullptr_t) { return nullptr; } inline std::nullptr_t RawPtr(std::nullptr_t) { return nullptr; }
......
...@@ -111,7 +111,7 @@ cc_test( ...@@ -111,7 +111,7 @@ cc_test(
size = "small", size = "small",
srcs = [ srcs = [
"escaping_test.cc", "escaping_test.cc",
"internal/escaping_test_common.inc", "internal/escaping_test_common.h",
], ],
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
visibility = ["//visibility:private"], visibility = ["//visibility:private"],
...@@ -127,7 +127,7 @@ cc_test( ...@@ -127,7 +127,7 @@ cc_test(
name = "escaping_benchmark", name = "escaping_benchmark",
srcs = [ srcs = [
"escaping_benchmark.cc", "escaping_benchmark.cc",
"internal/escaping_test_common.inc", "internal/escaping_test_common.h",
], ],
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
tags = ["benchmark"], tags = ["benchmark"],
...@@ -135,7 +135,7 @@ cc_test( ...@@ -135,7 +135,7 @@ cc_test(
deps = [ deps = [
":strings", ":strings",
"//absl/base", "//absl/base",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -199,7 +199,7 @@ cc_test( ...@@ -199,7 +199,7 @@ cc_test(
":strings", ":strings",
"//absl/base", "//absl/base",
"//absl/base:core_headers", "//absl/base:core_headers",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -240,7 +240,7 @@ cc_test( ...@@ -240,7 +240,7 @@ cc_test(
deps = [ deps = [
":strings", ":strings",
"//absl/base", "//absl/base",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -278,7 +278,7 @@ cc_test( ...@@ -278,7 +278,7 @@ cc_test(
deps = [ deps = [
":strings", ":strings",
"//absl/base", "//absl/base",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -295,6 +295,18 @@ cc_test( ...@@ -295,6 +295,18 @@ cc_test(
) )
cc_test( cc_test(
name = "ostringstream_benchmark",
srcs = ["internal/ostringstream_benchmark.cc"],
copts = ABSL_TEST_COPTS,
tags = ["benchmark"],
visibility = ["//visibility:private"],
deps = [
":internal",
"@com_github_google_benchmark//:benchmark_main",
],
)
cc_test(
name = "resize_uninitialized_test", name = "resize_uninitialized_test",
size = "small", size = "small",
srcs = [ srcs = [
...@@ -333,7 +345,7 @@ cc_test( ...@@ -333,7 +345,7 @@ cc_test(
deps = [ deps = [
":strings", ":strings",
"//absl/memory", "//absl/memory",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -358,7 +370,7 @@ cc_test( ...@@ -358,7 +370,7 @@ cc_test(
visibility = ["//visibility:private"], visibility = ["//visibility:private"],
deps = [ deps = [
":strings", ":strings",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -366,7 +378,7 @@ cc_test( ...@@ -366,7 +378,7 @@ cc_test(
name = "numbers_test", name = "numbers_test",
size = "small", size = "small",
srcs = [ srcs = [
"internal/numbers_test_common.inc", "internal/numbers_test_common.h",
"numbers_test.cc", "numbers_test.cc",
], ],
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
...@@ -411,3 +423,14 @@ cc_test( ...@@ -411,3 +423,14 @@ cc_test(
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
cc_test(
name = "char_map_benchmark",
srcs = ["internal/char_map_benchmark.cc"],
copts = ABSL_TEST_COPTS,
tags = ["benchmark"],
deps = [
":internal",
"@com_github_google_benchmark//:benchmark_main",
],
)
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/strings/internal/escaping_test_common.inc" #include "absl/strings/internal/escaping_test_common.h"
namespace { namespace {
...@@ -39,7 +39,7 @@ BENCHMARK(BM_CUnescapeHexString); ...@@ -39,7 +39,7 @@ BENCHMARK(BM_CUnescapeHexString);
void BM_WebSafeBase64Escape_string(benchmark::State& state) { void BM_WebSafeBase64Escape_string(benchmark::State& state) {
std::string raw; std::string raw;
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
for (const auto& test_set : base64_strings) { for (const auto& test_set : absl::strings_internal::base64_strings()) {
raw += std::string(test_set.plaintext); raw += std::string(test_set.plaintext);
} }
} }
...@@ -92,5 +92,3 @@ void BM_CEscape_MostEscaped(benchmark::State& state) { ...@@ -92,5 +92,3 @@ void BM_CEscape_MostEscaped(benchmark::State& state) {
BENCHMARK(BM_CEscape_MostEscaped)->Range(1, 1 << 14); BENCHMARK(BM_CEscape_MostEscaped)->Range(1, 1 << 14);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "absl/container/fixed_array.h" #include "absl/container/fixed_array.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/internal/escaping_test_common.inc" #include "absl/strings/internal/escaping_test_common.h"
namespace { namespace {
...@@ -575,7 +575,7 @@ TEST(Base64, EscapeAndUnescape) { ...@@ -575,7 +575,7 @@ TEST(Base64, EscapeAndUnescape) {
} }
// Now try the long strings, this tests the streaming // Now try the long strings, this tests the streaming
for (const auto& tc : base64_strings) { for (const auto& tc : absl::strings_internal::base64_strings()) {
std::string buffer; std::string buffer;
absl::WebSafeBase64Escape(tc.plaintext, &buffer); absl::WebSafeBase64Escape(tc.plaintext, &buffer);
EXPECT_EQ(tc.cyphertext, buffer); EXPECT_EQ(tc.cyphertext, buffer);
......
// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/strings/internal/char_map.h"
#include <cstdint>
#include "benchmark/benchmark.h"
namespace {
absl::strings_internal::Charmap MakeBenchmarkMap() {
absl::strings_internal::Charmap m;
uint32_t x[] = {0x0, 0x1, 0x2, 0x3, 0xf, 0xe, 0xd, 0xc};
for (uint32_t& t : x) t *= static_cast<uint32_t>(0x11111111UL);
for (uint32_t i = 0; i < 256; ++i) {
if ((x[i / 32] >> (i % 32)) & 1)
m = m | absl::strings_internal::Charmap::Char(i);
}
return m;
}
// Micro-benchmark for Charmap::contains.
void BM_Contains(benchmark::State& state) {
// Loop-body replicated 10 times to increase time per iteration.
// Argument continuously changed to avoid generating common subexpressions.
const absl::strings_internal::Charmap benchmark_map = MakeBenchmarkMap();
unsigned char c = 0;
int ops = 0;
for (auto _ : state) {
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
ops += benchmark_map.contains(c++);
}
benchmark::DoNotOptimize(ops);
}
BENCHMARK(BM_Contains);
// We don't bother benchmarking Charmap::IsZero or Charmap::IntersectsWith;
// their running time is data-dependent and it is not worth characterizing
// "typical" data.
} // namespace
...@@ -15,12 +15,22 @@ ...@@ -15,12 +15,22 @@
// This test contains common things needed by both escaping_test.cc and // This test contains common things needed by both escaping_test.cc and
// escaping_benchmark.cc. // escaping_benchmark.cc.
namespace { #ifndef ABSL_STRINGS_INTERNAL_ESCAPING_TEST_COMMON_H_
#define ABSL_STRINGS_INTERNAL_ESCAPING_TEST_COMMON_H_
struct { #include <array>
#include "absl/strings/string_view.h"
namespace absl {
namespace strings_internal {
struct base64_testcase {
absl::string_view plaintext; absl::string_view plaintext;
absl::string_view cyphertext; absl::string_view cyphertext;
} const base64_strings[] = { };
inline const std::array<base64_testcase, 5>& base64_strings() {
static const std::array<base64_testcase, 5> testcase{{
// Some google quotes // Some google quotes
// Cyphertext created with "uuencode (GNU sharutils) 4.6.3" // Cyphertext created with "uuencode (GNU sharutils) 4.6.3"
// (Note that we're testing the websafe encoding, though, so if // (Note that we're testing the websafe encoding, though, so if
...@@ -83,14 +93,16 @@ struct { ...@@ -83,14 +93,16 @@ struct {
"Y29tcGxldGVseSByZWFzb25hYmxlIHJlc3BvbnNlLiAtIE1hdHQgQ3V0dHMs" "Y29tcGxldGVseSByZWFzb25hYmxlIHJlc3BvbnNlLiAtIE1hdHQgQ3V0dHMs"
"IEdvb2dsZSBQbHVzCg" }, "IEdvb2dsZSBQbHVzCg" },
{ "It will still be a long time before machines approach human intelligence. " { "It will still be a long time before machines approach human "
"intelligence. "
"But luckily, machines don't actually have to be intelligent; " "But luckily, machines don't actually have to be intelligent; "
"they just have to fake it. Access to a wealth of information, " "they just have to fake it. Access to a wealth of information, "
"combined with a rudimentary decision-making capacity, " "combined with a rudimentary decision-making capacity, "
"can often be almost as useful. Of course, the results are better yet " "can often be almost as useful. Of course, the results are better yet "
"when coupled with intelligence. A reference librarian with access to " "when coupled with intelligence. A reference librarian with access to "
"a good search engine is a formidable tool." "a good search engine is a formidable tool."
" - Craig Silverstein, Siemens Pictures of the Future, Spring 2004" "\n", " - Craig Silverstein, Siemens Pictures of the Future, Spring 2004"
"\n",
"SXQgd2lsbCBzdGlsbCBiZSBhIGxvbmcgdGltZSBiZWZvcmUgbWFjaGluZXMg" "SXQgd2lsbCBzdGlsbCBiZSBhIGxvbmcgdGltZSBiZWZvcmUgbWFjaGluZXMg"
"YXBwcm9hY2ggaHVtYW4gaW50ZWxsaWdlbmNlLiBCdXQgbHVja2lseSwgbWFj" "YXBwcm9hY2ggaHVtYW4gaW50ZWxsaWdlbmNlLiBCdXQgbHVja2lseSwgbWFj"
...@@ -108,6 +120,12 @@ struct { ...@@ -108,6 +120,12 @@ struct {
// Degenerate edge case // Degenerate edge case
{ "", { "",
"" }, "" },
}; }};
return testcase;
}
} // namespace strings_internal
} // namespace absl
} // namespace #endif // ABSL_STRINGS_INTERNAL_ESCAPING_TEST_COMMON_H_
...@@ -15,10 +15,19 @@ ...@@ -15,10 +15,19 @@
// This file contains common things needed by numbers_test.cc, // This file contains common things needed by numbers_test.cc,
// numbers_legacy_test.cc and numbers_benchmark.cc. // numbers_legacy_test.cc and numbers_benchmark.cc.
namespace { #ifndef ABSL_STRINGS_INTERNAL_NUMBERS_TEST_COMMON_H_
#define ABSL_STRINGS_INTERNAL_NUMBERS_TEST_COMMON_H_
#include <array>
#include <cstdint>
#include <limits>
#include <string>
namespace absl {
namespace strings_internal {
template <typename IntType> template <typename IntType>
bool Itoa(IntType value, int base, std::string* destination) { inline bool Itoa(IntType value, int base, std::string* destination) {
destination->clear(); destination->clear();
if (base <= 1 || base > 36) { if (base <= 1 || base > 36) {
return false; return false;
...@@ -51,7 +60,10 @@ struct uint32_test_case { ...@@ -51,7 +60,10 @@ struct uint32_test_case {
bool expect_ok; bool expect_ok;
int base; // base to pass to the conversion function int base; // base to pass to the conversion function
uint32_t expected; uint32_t expected;
} const strtouint32_test_cases[] = { };
inline const std::array<uint32_test_case, 27>& strtouint32_test_cases() {
static const std::array<uint32_test_case, 27> test_cases{{
{"0xffffffff", true, 16, std::numeric_limits<uint32_t>::max()}, {"0xffffffff", true, 16, std::numeric_limits<uint32_t>::max()},
{"0x34234324", true, 16, 0x34234324}, {"0x34234324", true, 16, 0x34234324},
{"34234324", true, 16, 0x34234324}, {"34234324", true, 16, 0x34234324},
...@@ -87,14 +99,19 @@ struct uint32_test_case { ...@@ -87,14 +99,19 @@ struct uint32_test_case {
{"4294967296", false, 0, std::numeric_limits<uint32_t>::max()}, {"4294967296", false, 0, std::numeric_limits<uint32_t>::max()},
{"0x100000000", false, 0, std::numeric_limits<uint32_t>::max()}, {"0x100000000", false, 0, std::numeric_limits<uint32_t>::max()},
{nullptr, false, 0, 0}, {nullptr, false, 0, 0},
}; }};
return test_cases;
}
struct uint64_test_case { struct uint64_test_case {
const char* str; const char* str;
bool expect_ok; bool expect_ok;
int base; int base;
uint64_t expected; uint64_t expected;
} const strtouint64_test_cases[] = { };
inline const std::array<uint64_test_case, 34>& strtouint64_test_cases() {
static const std::array<uint64_test_case, 34> test_cases{{
{"0x3423432448783446", true, 16, int64_t{0x3423432448783446}}, {"0x3423432448783446", true, 16, int64_t{0x3423432448783446}},
{"3423432448783446", true, 16, int64_t{0x3423432448783446}}, {"3423432448783446", true, 16, int64_t{0x3423432448783446}},
...@@ -151,6 +168,11 @@ struct uint64_test_case { ...@@ -151,6 +168,11 @@ struct uint64_test_case {
// Base-10 std::string version. // Base-10 std::string version.
{"1234", true, 0, 1234}, {"1234", true, 0, 1234},
{nullptr, false, 0, 0}, {nullptr, false, 0, 0},
}; }};
return test_cases;
}
} // namespace strings_internal
} // namespace absl
} // namespace #endif // ABSL_STRINGS_INTERNAL_NUMBERS_TEST_COMMON_H_
// Copyright 2018 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/strings/internal/ostringstream.h"
#include <sstream>
#include <string>
#include "benchmark/benchmark.h"
namespace {
enum StringType {
kNone,
kStdString,
};
// Benchmarks for std::ostringstream.
template <StringType kOutput>
void BM_StdStream(benchmark::State& state) {
const int num_writes = state.range(0);
const int bytes_per_write = state.range(1);
const std::string payload(bytes_per_write, 'x');
for (auto _ : state) {
std::ostringstream strm;
benchmark::DoNotOptimize(strm);
for (int i = 0; i != num_writes; ++i) {
strm << payload;
}
switch (kOutput) {
case kNone: {
break;
}
case kStdString: {
std::string s = strm.str();
benchmark::DoNotOptimize(s);
break;
}
}
}
}
// Create the stream, optionally write to it, then destroy it.
BENCHMARK_TEMPLATE(BM_StdStream, kNone)
->ArgPair(0, 0)
->ArgPair(1, 16) // 16 bytes is small enough for SSO
->ArgPair(1, 256) // 256 bytes requires heap allocation
->ArgPair(1024, 256);
// Create the stream, write to it, get std::string out, then destroy.
BENCHMARK_TEMPLATE(BM_StdStream, kStdString)
->ArgPair(1, 16) // 16 bytes is small enough for SSO
->ArgPair(1, 256) // 256 bytes requires heap allocation
->ArgPair(1024, 256);
// Benchmarks for OStringStream.
template <StringType kOutput>
void BM_CustomStream(benchmark::State& state) {
const int num_writes = state.range(0);
const int bytes_per_write = state.range(1);
const std::string payload(bytes_per_write, 'x');
for (auto _ : state) {
std::string out;
absl::strings_internal::OStringStream strm(&out);
benchmark::DoNotOptimize(strm);
for (int i = 0; i != num_writes; ++i) {
strm << payload;
}
switch (kOutput) {
case kNone: {
break;
}
case kStdString: {
std::string s = out;
benchmark::DoNotOptimize(s);
break;
}
}
}
}
// Create the stream, optionally write to it, then destroy it.
BENCHMARK_TEMPLATE(BM_CustomStream, kNone)
->ArgPair(0, 0)
->ArgPair(1, 16) // 16 bytes is small enough for SSO
->ArgPair(1, 256) // 256 bytes requires heap allocation
->ArgPair(1024, 256);
// Create the stream, write to it, get std::string out, then destroy.
// It's not useful in practice to extract std::string from OStringStream; we
// measure it for completeness.
BENCHMARK_TEMPLATE(BM_CustomStream, kStdString)
->ArgPair(1, 16) // 16 bytes is small enough for SSO
->ArgPair(1, 256) // 256 bytes requires heap allocation
->ArgPair(1024, 256);
} // namespace
...@@ -52,12 +52,16 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out); ...@@ -52,12 +52,16 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out);
// //
// Converts the given std::string (optionally followed or preceded by ASCII // Converts the given std::string (optionally followed or preceded by ASCII
// whitespace) into a float, which may be rounded on overflow or underflow. // whitespace) into a float, which may be rounded on overflow or underflow.
// See http://en.cppreference.com/w/c/std::string/byte/strtof for details about the
// allowed formats for `str`.
ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str, float* value); ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str, float* value);
// SimpleAtod() // SimpleAtod()
// //
// Converts the given std::string (optionally followed or preceded by ASCII // Converts the given std::string (optionally followed or preceded by ASCII
// whitespace) into a double, which may be rounded on overflow or underflow. // whitespace) into a double, which may be rounded on overflow or underflow.
// See http://en.cppreference.com/w/c/std::string/byte/strtof for details about the
// allowed formats for `str`.
ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str, double* value); ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str, double* value);
// SimpleAtob() // SimpleAtob()
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/internal/numbers_test_common.inc" #include "absl/strings/internal/numbers_test_common.h"
namespace { namespace {
...@@ -48,6 +48,9 @@ using absl::numbers_internal::safe_strto64_base; ...@@ -48,6 +48,9 @@ using absl::numbers_internal::safe_strto64_base;
using absl::numbers_internal::safe_strtou32_base; using absl::numbers_internal::safe_strtou32_base;
using absl::numbers_internal::safe_strtou64_base; using absl::numbers_internal::safe_strtou64_base;
using absl::numbers_internal::SixDigitsToBuffer; using absl::numbers_internal::SixDigitsToBuffer;
using absl::strings_internal::Itoa;
using absl::strings_internal::strtouint32_test_cases;
using absl::strings_internal::strtouint64_test_cases;
using absl::SimpleAtoi; using absl::SimpleAtoi;
using testing::Eq; using testing::Eq;
using testing::MatchesRegex; using testing::MatchesRegex;
...@@ -654,8 +657,8 @@ TEST(stringtest, safe_strtou64_random) { ...@@ -654,8 +657,8 @@ TEST(stringtest, safe_strtou64_random) {
} }
TEST(stringtest, safe_strtou32_base) { TEST(stringtest, safe_strtou32_base) {
for (int i = 0; strtouint32_test_cases[i].str != nullptr; ++i) { for (int i = 0; strtouint32_test_cases()[i].str != nullptr; ++i) {
const auto& e = strtouint32_test_cases[i]; const auto& e = strtouint32_test_cases()[i];
uint32_t value; uint32_t value;
EXPECT_EQ(e.expect_ok, safe_strtou32_base(e.str, &value, e.base)) EXPECT_EQ(e.expect_ok, safe_strtou32_base(e.str, &value, e.base))
<< "str=\"" << e.str << "\" base=" << e.base; << "str=\"" << e.str << "\" base=" << e.base;
...@@ -667,8 +670,8 @@ TEST(stringtest, safe_strtou32_base) { ...@@ -667,8 +670,8 @@ TEST(stringtest, safe_strtou32_base) {
} }
TEST(stringtest, safe_strtou32_base_length_delimited) { TEST(stringtest, safe_strtou32_base_length_delimited) {
for (int i = 0; strtouint32_test_cases[i].str != nullptr; ++i) { for (int i = 0; strtouint32_test_cases()[i].str != nullptr; ++i) {
const auto& e = strtouint32_test_cases[i]; const auto& e = strtouint32_test_cases()[i];
std::string tmp(e.str); std::string tmp(e.str);
tmp.append("12"); // Adds garbage at the end. tmp.append("12"); // Adds garbage at the end.
...@@ -685,8 +688,8 @@ TEST(stringtest, safe_strtou32_base_length_delimited) { ...@@ -685,8 +688,8 @@ TEST(stringtest, safe_strtou32_base_length_delimited) {
} }
TEST(stringtest, safe_strtou64_base) { TEST(stringtest, safe_strtou64_base) {
for (int i = 0; strtouint64_test_cases[i].str != nullptr; ++i) { for (int i = 0; strtouint64_test_cases()[i].str != nullptr; ++i) {
const auto& e = strtouint64_test_cases[i]; const auto& e = strtouint64_test_cases()[i];
uint64_t value; uint64_t value;
EXPECT_EQ(e.expect_ok, safe_strtou64_base(e.str, &value, e.base)) EXPECT_EQ(e.expect_ok, safe_strtou64_base(e.str, &value, e.base))
<< "str=\"" << e.str << "\" base=" << e.base; << "str=\"" << e.str << "\" base=" << e.base;
...@@ -697,8 +700,8 @@ TEST(stringtest, safe_strtou64_base) { ...@@ -697,8 +700,8 @@ TEST(stringtest, safe_strtou64_base) {
} }
TEST(stringtest, safe_strtou64_base_length_delimited) { TEST(stringtest, safe_strtou64_base_length_delimited) {
for (int i = 0; strtouint64_test_cases[i].str != nullptr; ++i) { for (int i = 0; strtouint64_test_cases()[i].str != nullptr; ++i) {
const auto& e = strtouint64_test_cases[i]; const auto& e = strtouint64_test_cases()[i];
std::string tmp(e.str); std::string tmp(e.str);
tmp.append("12"); // Adds garbage at the end. tmp.append("12"); // Adds garbage at the end.
......
...@@ -138,5 +138,3 @@ void BM_DoubleToString_By_SixDigits(benchmark::State& state) { ...@@ -138,5 +138,3 @@ void BM_DoubleToString_By_SixDigits(benchmark::State& state) {
BENCHMARK(BM_DoubleToString_By_SixDigits); BENCHMARK(BM_DoubleToString_By_SixDigits);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -94,5 +94,3 @@ BENCHMARK(BM_JoinStreamable) ...@@ -94,5 +94,3 @@ BENCHMARK(BM_JoinStreamable)
->ArgPair(256, 256); ->ArgPair(256, 256);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -120,5 +120,3 @@ void BM_StrReplaceAll(benchmark::State& state) { ...@@ -120,5 +120,3 @@ void BM_StrReplaceAll(benchmark::State& state) {
BENCHMARK(BM_StrReplaceAll); BENCHMARK(BM_StrReplaceAll);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -154,5 +154,3 @@ BENCHMARK_TEMPLATE(BM_SplitStringWithOneCharNoVector, OneCharLiteral); ...@@ -154,5 +154,3 @@ BENCHMARK_TEMPLATE(BM_SplitStringWithOneCharNoVector, OneCharLiteral);
BENCHMARK_TEMPLATE(BM_SplitStringWithOneCharNoVector, OneCharStringLiteral); BENCHMARK_TEMPLATE(BM_SplitStringWithOneCharNoVector, OneCharStringLiteral);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -327,5 +327,3 @@ void BM_AppendToStringNative(benchmark::State& state) { ...@@ -327,5 +327,3 @@ void BM_AppendToStringNative(benchmark::State& state) {
BENCHMARK(BM_AppendToStringNative)->Range(1 << 3, 1 << 12); BENCHMARK(BM_AppendToStringNative)->Range(1 << 3, 1 << 12);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -99,7 +99,10 @@ class Arg { ...@@ -99,7 +99,10 @@ class Arg {
// Explicitly overload `const char*` so the compiler doesn't cast to `bool`. // Explicitly overload `const char*` so the compiler doesn't cast to `bool`.
Arg(const char* value) // NOLINT(runtime/explicit) Arg(const char* value) // NOLINT(runtime/explicit)
: piece_(absl::NullSafeStringView(value)) {} : piece_(absl::NullSafeStringView(value)) {}
Arg(const std::string& value) // NOLINT(runtime/explicit) template <typename Allocator>
Arg( // NOLINT
const std::basic_string<char, std::char_traits<char>, Allocator>&
value) noexcept
: piece_(value) {} : piece_(value) {}
Arg(absl::string_view value) // NOLINT(runtime/explicit) Arg(absl::string_view value) // NOLINT(runtime/explicit)
: piece_(value) {} : piece_(value) {}
......
...@@ -130,7 +130,7 @@ cc_test( ...@@ -130,7 +130,7 @@ cc_test(
deps = [ deps = [
":graphcycles_internal", ":graphcycles_internal",
"//absl/base", "//absl/base",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
...@@ -176,7 +176,7 @@ cc_test( ...@@ -176,7 +176,7 @@ cc_test(
":synchronization", ":synchronization",
":thread_pool", ":thread_pool",
"//absl/base", "//absl/base",
"@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main",
], ],
) )
......
...@@ -42,5 +42,3 @@ void BM_StressTest(benchmark::State& state) { ...@@ -42,5 +42,3 @@ void BM_StressTest(benchmark::State& state) {
BENCHMARK(BM_StressTest)->Range(2048, 1048576); BENCHMARK(BM_StressTest)->Range(2048, 1048576);
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -92,5 +92,3 @@ BENCHMARK(BM_ContendedMutex)->Threads(1); ...@@ -92,5 +92,3 @@ BENCHMARK(BM_ContendedMutex)->Threads(1);
BENCHMARK(BM_ContendedMutex)->ThreadPerCpu(); BENCHMARK(BM_ContendedMutex)->ThreadPerCpu();
} // namespace } // namespace
BENCHMARK_MAIN();
...@@ -81,10 +81,6 @@ cc_test( ...@@ -81,10 +81,6 @@ cc_test(
], ],
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
tags = [ tags = [
"no_test_android_arm",
"no_test_android_arm64",
"no_test_android_x86",
"no_test_ios_x86_64",
"no_test_loonix", "no_test_loonix",
], ],
deps = [ deps = [
......
...@@ -81,6 +81,11 @@ cc_test( ...@@ -81,6 +81,11 @@ cc_test(
size = "small", size = "small",
srcs = ["src/time_zone_format_test.cc"], srcs = ["src/time_zone_format_test.cc"],
data = [":zoneinfo"], data = [":zoneinfo"],
tags = [
"no_test_android_arm",
"no_test_android_arm64",
"no_test_android_x86",
],
deps = [ deps = [
":civil_time", ":civil_time",
":time_zone", ":time_zone",
...@@ -93,6 +98,11 @@ cc_test( ...@@ -93,6 +98,11 @@ cc_test(
size = "small", size = "small",
srcs = ["src/time_zone_lookup_test.cc"], srcs = ["src/time_zone_lookup_test.cc"],
data = [":zoneinfo"], data = [":zoneinfo"],
tags = [
"no_test_android_arm",
"no_test_android_arm64",
"no_test_android_x86",
],
deps = [ deps = [
":civil_time", ":civil_time",
":time_zone", ":time_zone",
...@@ -102,6 +112,24 @@ cc_test( ...@@ -102,6 +112,24 @@ cc_test(
### benchmarks ### benchmarks
cc_test(
name = "cctz_benchmark",
srcs = [
"src/cctz_benchmark.cc",
"src/time_zone_if.h",
"src/time_zone_impl.h",
"src/time_zone_info.h",
"src/tzfile.h",
],
linkstatic = 1,
tags = ["benchmark"],
deps = [
":civil_time",
":time_zone",
"@com_github_google_benchmark//:benchmark_main",
],
)
### examples ### examples
### binaries ### binaries
......
...@@ -463,8 +463,13 @@ TEST(Format, ExtendedSecondOffset) { ...@@ -463,8 +463,13 @@ TEST(Format, ExtendedSecondOffset) {
EXPECT_TRUE(load_time_zone("Europe/Moscow", &tz)); EXPECT_TRUE(load_time_zone("Europe/Moscow", &tz));
tp = convert(civil_second(1919, 6, 30, 23, 59, 59), utc); tp = convert(civil_second(1919, 6, 30, 23, 59, 59), utc);
if (tz.lookup(tp).offset == 4 * 60 * 60) {
// We're likely dealing with zoneinfo that doesn't support really old
// timestamps, so Europe/Moscow never looks to be on local mean time.
} else {
TestFormatSpecifier(tp, tz, "%E*z", "+04:31:19"); TestFormatSpecifier(tp, tz, "%E*z", "+04:31:19");
TestFormatSpecifier(tp, tz, "%Ez", "+04:31"); TestFormatSpecifier(tp, tz, "%Ez", "+04:31");
}
tp += seconds(1); tp += seconds(1);
TestFormatSpecifier(tp, tz, "%E*z", "+04:00:00"); TestFormatSpecifier(tp, tz, "%E*z", "+04:00:00");
} }
......
...@@ -193,6 +193,20 @@ cc_test( ...@@ -193,6 +193,20 @@ cc_test(
], ],
) )
cc_test(
name = "optional_exception_safety_test",
srcs = [
"optional_exception_safety_test.cc",
],
copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG,
deps = [
":optional",
"//absl/base:exception_safety_testing",
"@com_google_googletest//:gtest_main",
],
)
cc_library( cc_library(
name = "variant", name = "variant",
srcs = ["internal/variant.h"], srcs = ["internal/variant.h"],
......
...@@ -209,3 +209,20 @@ absl_test( ...@@ -209,3 +209,20 @@ absl_test(
) )
# test optional_exception_safety_test
set(OPTIONAL_EXCEPTION_SAFETY_TEST_SRC "optional_exception_safety_test.cc")
set(OPTIONAL_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
absl::optional
absl_base_internal_exception_safety_testing
)
absl_test(
TARGET
optional_exception_safety_test
SOURCES
${OPTIONAL_EXCEPTION_SAFETY_TEST_SRC}
PUBLIC_LIBRARIES
${OPTIONAL_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES}
PRIVATE_COMPILE_FLAGS
${ABSL_EXCEPTIONS_FLAG}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment