Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Unified Diff: net/base/mime_sniffer_perftest.cc

Issue 1058003005: Mime sniffer: reduce table from 256 bytes to 4 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit tests for ContainsControlCodes() Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/mime_sniffer_perftest.cc
diff --git a/net/base/mime_sniffer_perftest.cc b/net/base/mime_sniffer_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8a1f656ca64ca446f5fa3ae1b04e5e7584e6c12
--- /dev/null
+++ b/net/base/mime_sniffer_perftest.cc
@@ -0,0 +1,34 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/mime_sniffer.h"
+
+#include <vector>
+
+#include "base/test/perf_time_logger.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace {
+
+TEST(MimeSnifferTest, FastPathPerfTest) {
asanka 2015/04/29 23:17:44 Not very keen on this type of perftest that measur
Adam Rice 2015/05/07 16:52:50 I don't expect micro-benchmarks to be representati
asanka 2015/05/12 19:20:41 Interesting. Thanks for running the tests. I also
+ std::vector<char> plaintext(1 << 28, ' ');
+ base::PerfTimeLogger timer("MimeSnifferFastPathPerf_256MB");
+ ContainsControlCodes(&plaintext[0], plaintext.size());
+}
+
+TEST(MimeSnifferTest, SlowPathPerfTest) {
+ const size_t target_size = 1 << 28;
+ // The control characters force the code to do an array lookup. The "a" is
+ // there to make branch prediction harder.
+ std::string plaintext = "\ta\r\n";
+ plaintext.reserve(target_size);
+ while (plaintext.size() < target_size)
+ plaintext += plaintext;
+ base::PerfTimeLogger timer("MimeSnifferSlowPathPerf_256MB");
+ ContainsControlCodes(&plaintext[0], plaintext.size());
+}
+
+} // namespace net
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698