Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: mojo/edk/util/ref_counted_perftest.cc

Issue 1420713006: Revert "EDK: Move //mojo/edk/system/waitable_event* to edk/util." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/util/mutex_unittest.cc ('k') | mojo/edk/util/waitable_event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
17 namespace mojo { 13 namespace mojo {
18 namespace util { 14 namespace util {
19 namespace { 15 namespace {
20 16
21 class MyClass : public RefCountedThreadSafe<MyClass> { 17 class MyClass : public RefCountedThreadSafe<MyClass> {
22 public: 18 public:
23 static RefPtr<MyClass> Create() { 19 static RefPtr<MyClass> Create() {
24 return RefPtr<MyClass>(AdoptRef(new MyClass())); 20 return RefPtr<MyClass>(AdoptRef(new MyClass()));
25 } 21 }
26 22
27 private: 23 private:
28 friend class RefCountedThreadSafe<MyClass>; 24 friend class RefCountedThreadSafe<MyClass>;
29 25
30 MyClass() {} 26 MyClass() {}
31 ~MyClass() {} 27 ~MyClass() {}
32 }; 28 };
33 29
34 TEST(RefCountedPerfTest, OneThreadCreateAdoptDestroy) { 30 TEST(RefCountedPerfTest, OneThreadCreateAdoptDestroy) {
35 uint64_t iterations = 0; 31 uint64_t iterations = 0;
36 Stopwatch stopwatch; 32 system::test::Stopwatch stopwatch;
37 stopwatch.Start(); 33 stopwatch.Start();
38 do { 34 do {
39 for (size_t i = 0; i < 1000; i++, iterations++) { 35 for (size_t i = 0; i < 1000; i++, iterations++) {
40 RefPtr<MyClass> x = MyClass::Create(); 36 RefPtr<MyClass> x = MyClass::Create();
41 x = nullptr; 37 x = nullptr;
42 } 38 }
43 iterations++; 39 iterations++;
44 } while (stopwatch.Elapsed() < DeadlineFromMilliseconds(1000)); 40 } while (stopwatch.Elapsed() < system::test::DeadlineFromMilliseconds(1000));
45 double elapsed = stopwatch.Elapsed() / 1000000.0; 41 double elapsed = stopwatch.Elapsed() / 1000000.0;
46 42
47 LogPerfResult("OneThreadCreateAdoptDestroy", iterations / elapsed, 43 system::test::LogPerfResult("OneThreadCreateAdoptDestroy",
48 "iterations/s"); 44 iterations / elapsed, "iterations/s");
49 } 45 }
50 46
51 TEST(RefCountedPerfTest, OneThreadAssignRefPtr) { 47 TEST(RefCountedPerfTest, OneThreadAssignRefPtr) {
52 RefPtr<MyClass> x = MyClass::Create(); 48 RefPtr<MyClass> x = MyClass::Create();
53 uint64_t iterations = 0; 49 uint64_t iterations = 0;
54 Stopwatch stopwatch; 50 system::test::Stopwatch stopwatch;
55 stopwatch.Start(); 51 stopwatch.Start();
56 do { 52 do {
57 for (size_t i = 0; i < 1000; i++, iterations++) { 53 for (size_t i = 0; i < 1000; i++, iterations++) {
58 RefPtr<MyClass> y = x; 54 RefPtr<MyClass> y = x;
59 } 55 }
60 iterations++; 56 iterations++;
61 } while (stopwatch.Elapsed() < DeadlineFromMilliseconds(1000)); 57 } while (stopwatch.Elapsed() < system::test::DeadlineFromMilliseconds(1000));
62 double elapsed = stopwatch.Elapsed() / 1000000.0; 58 double elapsed = stopwatch.Elapsed() / 1000000.0;
63 59
64 LogPerfResult("OneThreadAssignRefPtr", iterations / elapsed, "iterations/s"); 60 system::test::LogPerfResult("OneThreadAssignRefPtr", iterations / elapsed,
61 "iterations/s");
65 } 62 }
66 63
67 // TODO(vtl): Add threaded perf tests. 64 // TODO(vtl): Add threaded perf tests.
68 65
69 } // namespace 66 } // namespace
70 } // namespace util 67 } // namespace util
71 } // namespace mojo 68 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/util/mutex_unittest.cc ('k') | mojo/edk/util/waitable_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698