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"
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
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
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
));
30 base::PerfTimeLogger
timer("Full_URL_Parse_AMillion");
32 for (int i
= 0; i
< 1000000; i
++)
33 url::ParseStandardURL(url
, url_len
, &parsed
);
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
));
50 TEST(URLParse
, TypicalURLParse
) {
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
);
65 // Includes both parsing and canonicalization with no mallocs.
66 TEST(URLParse
, TypicalURLParseCanon
) {
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
);
77 url::CanonicalizeStandardURL(typical_url1
, typical_url1_len
, parsed1
,
78 NULL
, &output
, &out_parsed
);
80 url::ParseStandardURL(typical_url2
, typical_url2_len
, &parsed2
);
82 url::CanonicalizeStandardURL(typical_url2
, typical_url2_len
, parsed2
,
83 NULL
, &output
, &out_parsed
);
85 url::ParseStandardURL(typical_url3
, typical_url3_len
, &parsed3
);
87 url::CanonicalizeStandardURL(typical_url3
, typical_url3_len
, parsed3
,
88 NULL
, &output
, &out_parsed
);
93 // Includes both parsing and canonicalization, and mallocs for the output.
94 TEST(URLParse
, TypicalURLParseCanonStdString
) {
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
);
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
);
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
);
116 url::StdStringCanonOutput
output3(&out3
);
117 url::CanonicalizeStandardURL(typical_url3
, typical_url3_len
, parsed3
,
118 NULL
, &output3
, &out_parsed
);
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
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
);