manifest_handler_perf_test.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2017 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. #include "extensions/common/common_manifest_handlers.h"
  5. #include "extensions/common/manifest_handler.h"
  6. #include "extensions/common/scoped_testing_manifest_handler_registry.h"
  7. #include "extensions/test/logging_timer.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace extensions {
  10. // This and the following test are used to monitor the performance
  11. // of the manifest handler registry initialization path, since
  12. // it was determined to be a large part of the extensions system
  13. // startup cost. They are prefixed with "MANUAL_" since they are
  14. // not run like regular unit tests. They can be run like this:
  15. // extensions_unittests --gtest_filter="ManifestHandlerPerfTest.*"
  16. // and should be run after any substantial changes to the related
  17. // code.
  18. TEST(ManifestHandlerPerfTest, MANUAL_CommonInitialize) {
  19. ScopedTestingManifestHandlerRegistry scoped_registry;
  20. static constexpr char kTimerId[] = "CommonInitialize";
  21. for (int i = 0; i < 100000; ++i) {
  22. {
  23. LoggingTimer timer(kTimerId);
  24. RegisterCommonManifestHandlers();
  25. ManifestHandler::FinalizeRegistration();
  26. }
  27. ManifestHandlerRegistry::ResetForTesting();
  28. }
  29. LoggingTimer::Print();
  30. }
  31. TEST(ManifestHandlerPerfTest, MANUAL_LookupTest) {
  32. ScopedTestingManifestHandlerRegistry scoped_registry;
  33. RegisterCommonManifestHandlers();
  34. ManifestHandler::FinalizeRegistration();
  35. ManifestHandlerRegistry* registry = ManifestHandlerRegistry::Get();
  36. ASSERT_TRUE(registry);
  37. std::vector<std::string> handler_names;
  38. handler_names.reserve(registry->handlers_.size());
  39. for (const auto& entry : registry->handlers_) {
  40. handler_names.push_back(entry.first);
  41. }
  42. static constexpr char kTimerId[] = "LookupTest";
  43. for (int i = 0; i < 100000; ++i) {
  44. LoggingTimer timer(kTimerId);
  45. for (const auto& name : handler_names) {
  46. registry->handlers_.find(name);
  47. }
  48. }
  49. LoggingTimer::Print();
  50. }
  51. TEST(ManifestHandlerPerfTest, MANUAL_CommonMeasureFinalization) {
  52. ScopedTestingManifestHandlerRegistry scoped_registry;
  53. static constexpr char kTimerId[] = "Finalize";
  54. for (int i = 0; i < 100000; ++i) {
  55. {
  56. RegisterCommonManifestHandlers();
  57. LoggingTimer timer(kTimerId);
  58. ManifestHandler::FinalizeRegistration();
  59. }
  60. ManifestHandlerRegistry::ResetForTesting();
  61. }
  62. LoggingTimer::Print();
  63. }
  64. } // namespace extensions