Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / perf / url_parse_perftest.cc
blob34065c12eeac13478ee96bf836c51de463836578
1 // Copyright (c) 2006-2008 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.
5 #include "base/test/perf_time_logger.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "url/gurl.h"
8 #include "url/third_party/mozilla/url_parse.h"
9 #include "url/url_canon.h"
10 #include "url/url_canon_stdstring.h"
12 // TODO(darin): chrome code should not depend on WebCore innards
13 #if 0
14 #pragma warning(push, 0)
16 // This is because we have multiple headers called "CString.h" and KURL.cpp
17 // can grab the wrong one.
18 #include "webkit/third_party/WebCore/platform/CString.h"
20 #define KURL WebKitKURL
21 #include "KURL.cpp"
22 #include "KURL.h"
23 #pragma warning(pop)
25 TEST(URLParse, FullURL) {
26 const char url[] = "http://me:pass@host/foo/bar.html;param?query=yes#ref";
27 int url_len = static_cast<int>(strlen(url));
29 url::Parsed parsed;
30 base::PerfTimeLogger timer("Full_URL_Parse_AMillion");
32 for (int i = 0; i < 1000000; i++)
33 url::ParseStandardURL(url, url_len, &parsed);
34 timer.Done();
37 namespace {
39 const char typical_url1[] = "http://www.google.com/search?q=url+parsing&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a";
40 int typical_url1_len = static_cast<int>(strlen(typical_url1));
42 const char typical_url2[] = "http://www.amazon.com/Stephen-King-Thrillers-Horror-People/dp/0766012336/ref=sr_1_2/133-4144931-4505264?ie=UTF8&s=books&qid=2144880915&sr=8-2";
43 int typical_url2_len = static_cast<int>(strlen(typical_url2));
45 const char typical_url3[] = "http://store.apple.com/1-800-MY-APPLE/WebObjects/AppleStore.woa/wa/RSLID?nnmm=browse&mco=578E9744&node=home/desktop/mac_pro";
46 int typical_url3_len = static_cast<int>(strlen(typical_url3));
48 } // namespace
50 TEST(URLParse, TypicalURLParse) {
51 url::Parsed parsed1;
52 url::Parsed parsed2;
53 url::Parsed parsed3;
55 // Do this 1/3 of a million times since we do 3 different URLs.
56 base::PerfTimeLogger parse_timer("Typical_URL_Parse_AMillion");
57 for (int i = 0; i < 333333; i++) {
58 url::ParseStandardURL(typical_url1, typical_url1_len, &parsed1);
59 url::ParseStandardURL(typical_url2, typical_url2_len, &parsed2);
60 url::ParseStandardURL(typical_url3, typical_url3_len, &parsed3);
62 parse_timer.Done();
65 // Includes both parsing and canonicalization with no mallocs.
66 TEST(URLParse, TypicalURLParseCanon) {
67 url::Parsed parsed1;
68 url::Parsed parsed2;
69 url::Parsed parsed3;
71 base::PerfTimeLogger canon_timer("Typical_Parse_Canon_AMillion");
72 url::Parsed out_parsed;
73 url::RawCanonOutput<1024> output;
74 for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M
75 url::ParseStandardURL(typical_url1, typical_url1_len, &parsed1);
76 output.set_length(0);
77 url::CanonicalizeStandardURL(typical_url1, typical_url1_len, parsed1,
78 NULL, &output, &out_parsed);
80 url::ParseStandardURL(typical_url2, typical_url2_len, &parsed2);
81 output.set_length(0);
82 url::CanonicalizeStandardURL(typical_url2, typical_url2_len, parsed2,
83 NULL, &output, &out_parsed);
85 url::ParseStandardURL(typical_url3, typical_url3_len, &parsed3);
86 output.set_length(0);
87 url::CanonicalizeStandardURL(typical_url3, typical_url3_len, parsed3,
88 NULL, &output, &out_parsed);
90 canon_timer.Done();
93 // Includes both parsing and canonicalization, and mallocs for the output.
94 TEST(URLParse, TypicalURLParseCanonStdString) {
95 url::Parsed parsed1;
96 url::Parsed parsed2;
97 url::Parsed parsed3;
99 base::PerfTimeLogger canon_timer("Typical_Parse_Canon_AMillion");
100 url::Parsed out_parsed;
101 for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M
102 url::ParseStandardURL(typical_url1, typical_url1_len, &parsed1);
103 std::string out1;
104 url::StdStringCanonOutput output1(&out1);
105 url::CanonicalizeStandardURL(typical_url1, typical_url1_len, parsed1,
106 NULL, &output1, &out_parsed);
108 url::ParseStandardURL(typical_url2, typical_url2_len, &parsed2);
109 std::string out2;
110 url::StdStringCanonOutput output2(&out2);
111 url::CanonicalizeStandardURL(typical_url2, typical_url2_len, parsed2,
112 NULL, &output2, &out_parsed);
114 url::ParseStandardURL(typical_url3, typical_url3_len, &parsed3);
115 std::string out3;
116 url::StdStringCanonOutput output3(&out3);
117 url::CanonicalizeStandardURL(typical_url3, typical_url3_len, parsed3,
118 NULL, &output3, &out_parsed);
120 canon_timer.Done();
123 TEST(URLParse, GURL) {
124 // Don't want to time creating the input strings.
125 std::string stdurl1(typical_url1);
126 std::string stdurl2(typical_url2);
127 std::string stdurl3(typical_url3);
129 base::PerfTimeLogger gurl_timer("Typical_GURL_AMillion");
130 for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M
131 GURL gurl1(stdurl1);
132 GURL gurl2(stdurl2);
133 GURL gurl3(stdurl3);
135 gurl_timer.Done();
138 // TODO(darin): chrome code should not depend on WebCore innards
139 TEST(URLParse, KURL) {
140 base::PerfTimeLogger timer_kurl("Typical_KURL_AMillion");
141 for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M
142 WebCore::WebKitKURL kurl1(typical_url1);
143 WebCore::WebKitKURL kurl2(typical_url2);
144 WebCore::WebKitKURL kurl3(typical_url3);
146 timer_kurl.Done();
149 #endif