| 6 |
| 7 | #include <cinttypes> |
| 8 |
| 9 | #include "base/time/time.h" |
| 10 | #include "build/build_config.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 | namespace base { |
| 14 |
| 15 | template <typename String> |
| 16 | void MeasureIsStringASCII(size_t str_length, size_t non_ascii_pos) { |
| 17 | String str(str_length, 'A'); |
| 18 | if (non_ascii_pos < str_length) |
| 19 | str[non_ascii_pos] = '\xAF'; |
| 20 |
| 21 | TimeTicks t0 = TimeTicks::Now(); |
| 22 | for (size_t i = 0; i < 10000000; ++i) |
| 23 | IsStringASCII(str); |
| 24 | TimeDelta time = TimeTicks::Now() - t0; |
| 25 | printf( |
| 26 | "char-size:\t%zu\tlength:\t%zu\tnon-ascii-pos:\t%zu\ttime-ms:\t%" PRIu64 |
| 27 | "\n", |
| 28 | sizeof(typename String::value_type), str_length, non_ascii_pos, |
| 29 | time.InMilliseconds()); |
| 30 | } |
| 31 |
| 32 | TEST(StringUtilTest, DISABLED_IsStringASCIIPerf) { |
| 33 | for (size_t str_length = 4; str_length <= 1024; str_length *= 2) { |
| 34 | for (size_t non_ascii_loc = 0; non_ascii_loc < 3; ++non_ascii_loc) { |
| 35 | size_t non_ascii_pos = str_length * non_ascii_loc / 2 + 2; |
| 36 | MeasureIsStringASCII<std::string>(str_length, non_ascii_pos); |
| 37 | MeasureIsStringASCII<string16>(str_length, non_ascii_pos); |
| 38 | #if defined(WCHAR_T_IS_UTF32) |
| 39 | MeasureIsStringASCII<std::basic_string<wchar_t>>(str_length, |
| 40 | non_ascii_pos); |
| 41 | #endif |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 |
| 46 | } // namespace base |
| 47 |