| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <stdint.h> | 5 #include <stdint.h> | 
| 6 | 6 | 
| 7 #include "mojo/edk/system/test/perf_log.h" | 7 #include "mojo/edk/system/test/perf_log.h" | 
| 8 #include "mojo/edk/system/test/stopwatch.h" | 8 #include "mojo/edk/system/test/stopwatch.h" | 
| 9 #include "mojo/edk/system/test/timeouts.h" | 9 #include "mojo/edk/system/test/timeouts.h" | 
| 10 #include "mojo/edk/util/ref_counted.h" | 10 #include "mojo/edk/util/ref_counted.h" | 
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" | 
| 12 | 12 | 
|  | 13 using mojo::system::test::DeadlineFromMilliseconds; | 
|  | 14 using mojo::system::test::LogPerfResult; | 
|  | 15 using mojo::system::test::Stopwatch; | 
|  | 16 | 
| 13 namespace mojo { | 17 namespace mojo { | 
| 14 namespace util { | 18 namespace util { | 
| 15 namespace { | 19 namespace { | 
| 16 | 20 | 
| 17 class MyClass : public RefCountedThreadSafe<MyClass> { | 21 class MyClass : public RefCountedThreadSafe<MyClass> { | 
| 18  public: | 22  public: | 
| 19   static RefPtr<MyClass> Create() { | 23   static RefPtr<MyClass> Create() { | 
| 20     return RefPtr<MyClass>(AdoptRef(new MyClass())); | 24     return RefPtr<MyClass>(AdoptRef(new MyClass())); | 
| 21   } | 25   } | 
| 22 | 26 | 
| 23  private: | 27  private: | 
| 24   friend class RefCountedThreadSafe<MyClass>; | 28   friend class RefCountedThreadSafe<MyClass>; | 
| 25 | 29 | 
| 26   MyClass() {} | 30   MyClass() {} | 
| 27   ~MyClass() {} | 31   ~MyClass() {} | 
| 28 }; | 32 }; | 
| 29 | 33 | 
| 30 TEST(RefCountedPerfTest, OneThreadCreateAdoptDestroy) { | 34 TEST(RefCountedPerfTest, OneThreadCreateAdoptDestroy) { | 
| 31   uint64_t iterations = 0; | 35   uint64_t iterations = 0; | 
| 32   system::test::Stopwatch stopwatch; | 36   Stopwatch stopwatch; | 
| 33   stopwatch.Start(); | 37   stopwatch.Start(); | 
| 34   do { | 38   do { | 
| 35     for (size_t i = 0; i < 1000; i++, iterations++) { | 39     for (size_t i = 0; i < 1000; i++, iterations++) { | 
| 36       RefPtr<MyClass> x = MyClass::Create(); | 40       RefPtr<MyClass> x = MyClass::Create(); | 
| 37       x = nullptr; | 41       x = nullptr; | 
| 38     } | 42     } | 
| 39     iterations++; | 43     iterations++; | 
| 40   } while (stopwatch.Elapsed() < system::test::DeadlineFromMilliseconds(1000)); | 44   } while (stopwatch.Elapsed() < DeadlineFromMilliseconds(1000)); | 
| 41   double elapsed = stopwatch.Elapsed() / 1000000.0; | 45   double elapsed = stopwatch.Elapsed() / 1000000.0; | 
| 42 | 46 | 
| 43   system::test::LogPerfResult("OneThreadCreateAdoptDestroy", | 47   LogPerfResult("OneThreadCreateAdoptDestroy", iterations / elapsed, | 
| 44                               iterations / elapsed, "iterations/s"); | 48                 "iterations/s"); | 
| 45 } | 49 } | 
| 46 | 50 | 
| 47 TEST(RefCountedPerfTest, OneThreadAssignRefPtr) { | 51 TEST(RefCountedPerfTest, OneThreadAssignRefPtr) { | 
| 48   RefPtr<MyClass> x = MyClass::Create(); | 52   RefPtr<MyClass> x = MyClass::Create(); | 
| 49   uint64_t iterations = 0; | 53   uint64_t iterations = 0; | 
| 50   system::test::Stopwatch stopwatch; | 54   Stopwatch stopwatch; | 
| 51   stopwatch.Start(); | 55   stopwatch.Start(); | 
| 52   do { | 56   do { | 
| 53     for (size_t i = 0; i < 1000; i++, iterations++) { | 57     for (size_t i = 0; i < 1000; i++, iterations++) { | 
| 54       RefPtr<MyClass> y = x; | 58       RefPtr<MyClass> y = x; | 
| 55     } | 59     } | 
| 56     iterations++; | 60     iterations++; | 
| 57   } while (stopwatch.Elapsed() < system::test::DeadlineFromMilliseconds(1000)); | 61   } while (stopwatch.Elapsed() < DeadlineFromMilliseconds(1000)); | 
| 58   double elapsed = stopwatch.Elapsed() / 1000000.0; | 62   double elapsed = stopwatch.Elapsed() / 1000000.0; | 
| 59 | 63 | 
| 60   system::test::LogPerfResult("OneThreadAssignRefPtr", iterations / elapsed, | 64   LogPerfResult("OneThreadAssignRefPtr", iterations / elapsed, "iterations/s"); | 
| 61                               "iterations/s"); |  | 
| 62 } | 65 } | 
| 63 | 66 | 
| 64 // TODO(vtl): Add threaded perf tests. | 67 // TODO(vtl): Add threaded perf tests. | 
| 65 | 68 | 
| 66 }  // namespace | 69 }  // namespace | 
| 67 }  // namespace util | 70 }  // namespace util | 
| 68 }  // namespace mojo | 71 }  // namespace mojo | 
| OLD | NEW | 
|---|