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. 4 5#include "base/test/perf_time_logger.h" 6#include "testing/gtest/include/gtest/gtest.h" 7#include "url/gurl.h" 8#include "url/url_canon.h" 9#include "url/url_canon_stdstring.h" 10#include "url/url_parse.h" 11 12// TODO(darin): chrome code should not depend on WebCore innards 13#if 0 14#pragma warning(push, 0) 15 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" 19 20#define KURL WebKitKURL 21#include "KURL.cpp" 22#include "KURL.h" 23#pragma warning(pop) 24 25TEST(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)); 28 29 url_parse::Parsed parsed; 30 base::PerfTimeLogger timer("Full_URL_Parse_AMillion"); 31 32 for (int i = 0; i < 1000000; i++) 33 url_parse::ParseStandardURL(url, url_len, &parsed); 34 timer.Done(); 35} 36 37namespace { 38 39const 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"; 40int typical_url1_len = static_cast<int>(strlen(typical_url1)); 41 42const 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"; 43int typical_url2_len = static_cast<int>(strlen(typical_url2)); 44 45const 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"; 46int typical_url3_len = static_cast<int>(strlen(typical_url3)); 47 48} // namespace 49 50TEST(URLParse, TypicalURLParse) { 51 url_parse::Parsed parsed1; 52 url_parse::Parsed parsed2; 53 url_parse::Parsed parsed3; 54 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_parse::ParseStandardURL(typical_url1, typical_url1_len, &parsed1); 59 url_parse::ParseStandardURL(typical_url2, typical_url2_len, &parsed2); 60 url_parse::ParseStandardURL(typical_url3, typical_url3_len, &parsed3); 61 } 62 parse_timer.Done(); 63} 64 65// Includes both parsing and canonicalization with no mallocs. 66TEST(URLParse, TypicalURLParseCanon) { 67 url_parse::Parsed parsed1; 68 url_parse::Parsed parsed2; 69 url_parse::Parsed parsed3; 70 71 base::PerfTimeLogger canon_timer("Typical_Parse_Canon_AMillion"); 72 url_parse::Parsed out_parsed; 73 url_canon::RawCanonOutput<1024> output; 74 for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M 75 url_parse::ParseStandardURL(typical_url1, typical_url1_len, &parsed1); 76 output.set_length(0); 77 url_canon::CanonicalizeStandardURL(typical_url1, typical_url1_len, parsed1, 78 NULL, &output, &out_parsed); 79 80 url_parse::ParseStandardURL(typical_url2, typical_url2_len, &parsed2); 81 output.set_length(0); 82 url_canon::CanonicalizeStandardURL(typical_url2, typical_url2_len, parsed2, 83 NULL, &output, &out_parsed); 84 85 url_parse::ParseStandardURL(typical_url3, typical_url3_len, &parsed3); 86 output.set_length(0); 87 url_canon::CanonicalizeStandardURL(typical_url3, typical_url3_len, parsed3, 88 NULL, &output, &out_parsed); 89 } 90 canon_timer.Done(); 91} 92 93// Includes both parsing and canonicalization, and mallocs for the output. 94TEST(URLParse, TypicalURLParseCanonStdString) { 95 url_parse::Parsed parsed1; 96 url_parse::Parsed parsed2; 97 url_parse::Parsed parsed3; 98 99 base::PerfTimeLogger canon_timer("Typical_Parse_Canon_AMillion"); 100 url_parse::Parsed out_parsed; 101 for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M 102 url_parse::ParseStandardURL(typical_url1, typical_url1_len, &parsed1); 103 std::string out1; 104 url_canon::StdStringCanonOutput output1(&out1); 105 url_canon::CanonicalizeStandardURL(typical_url1, typical_url1_len, parsed1, 106 NULL, &output1, &out_parsed); 107 108 url_parse::ParseStandardURL(typical_url2, typical_url2_len, &parsed2); 109 std::string out2; 110 url_canon::StdStringCanonOutput output2(&out2); 111 url_canon::CanonicalizeStandardURL(typical_url2, typical_url2_len, parsed2, 112 NULL, &output2, &out_parsed); 113 114 url_parse::ParseStandardURL(typical_url3, typical_url3_len, &parsed3); 115 std::string out3; 116 url_canon::StdStringCanonOutput output3(&out3); 117 url_canon::CanonicalizeStandardURL(typical_url3, typical_url3_len, parsed3, 118 NULL, &output3, &out_parsed); 119 } 120 canon_timer.Done(); 121} 122 123TEST(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); 128 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); 134 } 135 gurl_timer.Done(); 136} 137 138// TODO(darin): chrome code should not depend on WebCore innards 139TEST(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); 145 } 146 timer_kurl.Done(); 147} 148 149#endif 150