| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This small program is used to measure the performance of the various | 5 // This small program is used to measure the performance of the various |
| 6 // resize algorithms offered by the ImageOperations::Resize function. | 6 // resize algorithms offered by the ImageOperations::Resize function. |
| 7 // It will generate an empty source bitmap, and rescale it to specified | 7 // It will generate an empty source bitmap, and rescale it to specified |
| 8 // dimensions. It will repeat this operation multiple time to get more accurate | 8 // dimensions. It will repeat this operation multiple time to get more accurate |
| 9 // average throughput. Because it uses elapsed time to do its math, it is only | 9 // average throughput. Because it uses elapsed time to do its math, it is only |
| 10 // accurate on an idle system (but that approach was deemed more accurate | 10 // accurate on an idle system (but that approach was deemed more accurate |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 class Benchmark { | 137 class Benchmark { |
| 138 public: | 138 public: |
| 139 static const int kDefaultNumberIterations; | 139 static const int kDefaultNumberIterations; |
| 140 static const skia::ImageOperations::ResizeMethod kDefaultResizeMethod; | 140 static const skia::ImageOperations::ResizeMethod kDefaultResizeMethod; |
| 141 | 141 |
| 142 Benchmark() | 142 Benchmark() |
| 143 : num_iterations_(kDefaultNumberIterations), | 143 : num_iterations_(kDefaultNumberIterations), |
| 144 method_(kDefaultResizeMethod) {} | 144 method_(kDefaultResizeMethod) {} |
| 145 | 145 |
| 146 // Returns true if command line parsing was successful, false otherwise. | 146 // Returns true if command line parsing was successful, false otherwise. |
| 147 bool ParseArgs(const CommandLine* command_line); | 147 bool ParseArgs(const base::CommandLine* command_line); |
| 148 | 148 |
| 149 // Returns true if successful, false otherwise. | 149 // Returns true if successful, false otherwise. |
| 150 bool Run() const; | 150 bool Run() const; |
| 151 | 151 |
| 152 static void Usage(); | 152 static void Usage(); |
| 153 private: | 153 private: |
| 154 int num_iterations_; | 154 int num_iterations_; |
| 155 skia::ImageOperations::ResizeMethod method_; | 155 skia::ImageOperations::ResizeMethod method_; |
| 156 Dimensions source_; | 156 Dimensions source_; |
| 157 Dimensions dest_; | 157 Dimensions dest_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 169 " -source wxh: specify source width and height\n" | 169 " -source wxh: specify source width and height\n" |
| 170 " -destination wxh: specify destination width and height\n" | 170 " -destination wxh: specify destination width and height\n" |
| 171 " -iter i: perform i iterations (default:%d)\n" | 171 " -iter i: perform i iterations (default:%d)\n" |
| 172 " -method m: use method m (default:%s), which can be:", | 172 " -method m: use method m (default:%s), which can be:", |
| 173 Benchmark::kDefaultNumberIterations, | 173 Benchmark::kDefaultNumberIterations, |
| 174 MethodToString(Benchmark::kDefaultResizeMethod)); | 174 MethodToString(Benchmark::kDefaultResizeMethod)); |
| 175 PrintMethods(); | 175 PrintMethods(); |
| 176 printf("\n -help: prints this help and exits\n"); | 176 printf("\n -help: prints this help and exits\n"); |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool Benchmark::ParseArgs(const CommandLine* command_line) { | 179 bool Benchmark::ParseArgs(const base::CommandLine* command_line) { |
| 180 const CommandLine::SwitchMap& switches = command_line->GetSwitches(); | 180 const base::CommandLine::SwitchMap& switches = command_line->GetSwitches(); |
| 181 bool fNeedHelp = false; | 181 bool fNeedHelp = false; |
| 182 | 182 |
| 183 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | 183 for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
| 184 iter != switches.end(); | 184 iter != switches.end(); |
| 185 ++iter) { | 185 ++iter) { |
| 186 const std::string& s = iter->first; | 186 const std::string& s = iter->first; |
| 187 std::string value; | 187 std::string value; |
| 188 #if defined(OS_WIN) | 188 #if defined(OS_WIN) |
| 189 value = base::WideToUTF8(iter->second); | 189 value = base::WideToUTF8(iter->second); |
| 190 #else | 190 #else |
| 191 value = iter->second; | 191 value = iter->second; |
| 192 #endif | 192 #endif |
| 193 if (s == "source") { | 193 if (s == "source") { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 GetBitmapSize(&source), GetBitmapSize(&dest)); | 255 GetBitmapSize(&source), GetBitmapSize(&dest)); |
| 256 | 256 |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 // A small class to automatically call Reset on the global command line to | 260 // A small class to automatically call Reset on the global command line to |
| 261 // avoid nasty valgrind complaints for the leak of the global command line. | 261 // avoid nasty valgrind complaints for the leak of the global command line. |
| 262 class CommandLineAutoReset { | 262 class CommandLineAutoReset { |
| 263 public: | 263 public: |
| 264 CommandLineAutoReset(int argc, char** argv) { | 264 CommandLineAutoReset(int argc, char** argv) { |
| 265 CommandLine::Init(argc, argv); | 265 base::CommandLine::Init(argc, argv); |
| 266 } | 266 } |
| 267 ~CommandLineAutoReset() { | 267 ~CommandLineAutoReset() { |
| 268 CommandLine::Reset(); | 268 base::CommandLine::Reset(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 const CommandLine* Get() const { | 271 const base::CommandLine* Get() const { |
| 272 return CommandLine::ForCurrentProcess(); | 272 return base::CommandLine::ForCurrentProcess(); |
| 273 } | 273 } |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 } // namespace | 276 } // namespace |
| 277 | 277 |
| 278 int main(int argc, char** argv) { | 278 int main(int argc, char** argv) { |
| 279 Benchmark bench; | 279 Benchmark bench; |
| 280 CommandLineAutoReset command_line(argc, argv); | 280 CommandLineAutoReset command_line(argc, argv); |
| 281 | 281 |
| 282 if (!bench.ParseArgs(command_line.Get())) { | 282 if (!bench.ParseArgs(command_line.Get())) { |
| 283 Benchmark::Usage(); | 283 Benchmark::Usage(); |
| 284 return 1; | 284 return 1; |
| 285 } | 285 } |
| 286 | 286 |
| 287 if (!bench.Run()) { | 287 if (!bench.Run()) { |
| 288 printf("Failed to run benchmark\n"); | 288 printf("Failed to run benchmark\n"); |
| 289 return 1; | 289 return 1; |
| 290 } | 290 } |
| 291 | 291 |
| 292 return 0; | 292 return 0; |
| 293 } | 293 } |
| OLD | NEW |