| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/mime_sniffer.h" | 5 #include "net/base/mime_sniffer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bits.h" | 9 #include "base/bits.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 TEST(MimeSnifferTest, PlainTextPerfTest) { | 80 TEST(MimeSnifferTest, PlainTextPerfTest) { |
| 81 // Android systems have a relatively small CPU cache (512KB to 2MB). | 81 // Android systems have a relatively small CPU cache (512KB to 2MB). |
| 82 // It is better if the test data fits in cache so that we are not just | 82 // It is better if the test data fits in cache so that we are not just |
| 83 // testing bus bandwidth. | 83 // testing bus bandwidth. |
| 84 const size_t kTargetSize = 1 << 18; // 256KB | 84 const size_t kTargetSize = 1 << 18; // 256KB |
| 85 const size_t kWarmupIterations = 16; | 85 const size_t kWarmupIterations = 16; |
| 86 const size_t kMeasuredIterations = 1 << 15; | 86 const size_t kMeasuredIterations = 1 << 15; |
| 87 std::string plaintext = kRepresentativePlainText; | 87 std::string plaintext = kRepresentativePlainText; |
| 88 // The purpose of the static_cast<size_t>() here is to prevent MSVC from | 88 size_t expected_size = plaintext.size() << base::bits::Log2Ceiling( |
| 89 // complaining about an implicit promotion to 64 bits when compiling 64-bit. | 89 kTargetSize / plaintext.size()); |
| 90 size_t expected_size = | |
| 91 plaintext.size() * | |
| 92 static_cast<size_t>( | |
| 93 1u << base::bits::Log2Ceiling(kTargetSize / plaintext.size())); | |
| 94 plaintext.reserve(expected_size); | 90 plaintext.reserve(expected_size); |
| 95 while (plaintext.size() < kTargetSize) | 91 while (plaintext.size() < kTargetSize) |
| 96 plaintext += plaintext; | 92 plaintext += plaintext; |
| 97 DCHECK_EQ(expected_size, plaintext.size()); | 93 DCHECK_EQ(expected_size, plaintext.size()); |
| 98 RunLooksLikeBinary(plaintext, kWarmupIterations); | 94 RunLooksLikeBinary(plaintext, kWarmupIterations); |
| 99 base::ElapsedTimer elapsed_timer; | 95 base::ElapsedTimer elapsed_timer; |
| 100 RunLooksLikeBinary(plaintext, kMeasuredIterations); | 96 RunLooksLikeBinary(plaintext, kMeasuredIterations); |
| 101 LOG(INFO) << (elapsed_timer.Elapsed().InMicroseconds() * 1000 * 1024 / | 97 LOG(INFO) << (elapsed_timer.Elapsed().InMicroseconds() * 1000 * 1024 / |
| 102 (static_cast<int64_t>(plaintext.size()) * kMeasuredIterations)) | 98 (static_cast<int64_t>(plaintext.size()) * kMeasuredIterations)) |
| 103 << "ns per KB"; | 99 << "ns per KB"; |
| 104 } | 100 } |
| 105 | 101 |
| 106 } // namespace net | 102 } // namespace net |
| 107 } // namespace | 103 } // namespace |
| OLD | NEW |