Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/mime_sniffer.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/timer/elapsed_timer.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace net { | |
| 14 namespace { | |
| 15 | |
| 16 // This text is supposed to be representative of a plain text file the browser | |
| 17 // might encounter, including a variation in line lengths and blank | |
| 18 // lines. CRLF is used as the line-terminator to make it slightly more | |
| 19 // difficult. It is roughly 1KB. | |
| 20 const char kRepresentativePlainText[] = | |
| 21 "The Tragedie of Hamlet\r\n" | |
| 22 "\r\n" | |
| 23 "Actus Primus. Scoena Prima.\r\n" | |
| 24 "\r\n" | |
| 25 "Enter Barnardo and Francisco two Centinels.\r\n" | |
| 26 "\r\n" | |
| 27 " Barnardo. Who's there?\r\n" | |
| 28 " Fran. Nay answer me: Stand & vnfold\r\n" | |
| 29 "your selfe\r\n" | |
| 30 "\r\n" | |
| 31 " Bar. Long liue the King\r\n" | |
| 32 "\r\n" | |
| 33 " Fran. Barnardo?\r\n" | |
| 34 " Bar. He\r\n" | |
| 35 "\r\n" | |
| 36 " Fran. You come most carefully vpon your houre\r\n" | |
| 37 "\r\n" | |
| 38 " Bar. 'Tis now strook twelue, get thee to bed Francisco\r\n" | |
| 39 "\r\n" | |
| 40 " Fran. For this releefe much thankes: 'Tis bitter cold,\r\n" | |
| 41 "And I am sicke at heart\r\n" | |
| 42 "\r\n" | |
| 43 " Barn. Haue you had quiet Guard?\r\n" | |
| 44 " Fran. Not a Mouse stirring\r\n" | |
| 45 "\r\n" | |
| 46 " Barn. Well, goodnight. If you do meet Horatio and\r\n" | |
| 47 "Marcellus, the Riuals of my Watch, bid them make hast.\r\n" | |
| 48 "Enter Horatio and Marcellus.\r\n" | |
| 49 "\r\n" | |
| 50 " Fran. I thinke I heare them. Stand: who's there?\r\n" | |
| 51 " Hor. Friends to this ground\r\n" | |
| 52 "\r\n" | |
| 53 " Mar. And Leige-men to the Dane\r\n" | |
| 54 "\r\n" | |
| 55 " Fran. Giue you good night\r\n" | |
| 56 "\r\n" | |
| 57 " Mar. O farwel honest Soldier, who hath relieu'd you?\r\n" | |
| 58 " Fra. Barnardo ha's my place: giue you goodnight.\r\n" | |
| 59 "\r\n" | |
| 60 "Exit Fran.\r\n" | |
| 61 "\r\n" | |
| 62 " Mar. Holla Barnardo\r\n" | |
| 63 "\r\n" | |
| 64 " Bar. Say, what is Horatio there?\r\n" | |
| 65 " Hor. A peece of him\r\n" | |
| 66 "\r\n" | |
| 67 " Bar. Welcome Horatio, welcome good Marcellus\r\n" | |
| 68 "\r\n"; | |
| 69 | |
| 70 void RunLooksLikeBinary(const std::string& plaintext, size_t iterations) { | |
| 71 bool looks_like_binary = false; | |
| 72 for (size_t i = 0; i < iterations; ++i) { | |
| 73 if (LooksLikeBinary(&plaintext[0], plaintext.size())) | |
| 74 looks_like_binary = true; | |
| 75 } | |
| 76 CHECK(!looks_like_binary); | |
| 77 } | |
| 78 | |
| 79 TEST(MimeSnifferTest, PlainTextPerfTest) { | |
| 80 // Android systems have a relatively small CPU cache (512KB to 2MB). | |
| 81 // It is better if the test data fits in cache so that we are not just | |
| 82 // testing bus bandwidth. | |
| 83 const size_t kTargetSize = 1 << 18; // 256KB | |
| 84 const size_t kWarmupIterations = 16; | |
| 85 const size_t kMeasuredIterations = 1 << 15; | |
| 86 std::string plaintext = kRepresentativePlainText; | |
| 87 plaintext.reserve(kTargetSize + plaintext.size() % kTargetSize); | |
|
asanka
2015/05/12 19:20:41
ISTM this should be:
plaintext.reserve(plaintext.
Adam Rice
2015/05/18 01:02:56
Good catch! Thanks.
| |
| 88 while (plaintext.size() < kTargetSize) | |
| 89 plaintext += plaintext; | |
| 90 RunLooksLikeBinary(plaintext, kWarmupIterations); | |
| 91 base::ElapsedTimer elapsed_timer; | |
| 92 RunLooksLikeBinary(plaintext, kMeasuredIterations); | |
| 93 LOG(INFO) << (elapsed_timer.Elapsed().InMicroseconds() * 1000 * 1024 / | |
| 94 (static_cast<int64>(plaintext.size()) * kMeasuredIterations)) | |
| 95 << "ns per KB"; | |
| 96 } | |
| 97 | |
| 98 } // namespace net | |
| 99 } // namespace | |
| OLD | NEW |