OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/base/platform/time.h" | 5 #include "src/base/platform/time.h" |
6 | 6 |
7 #if V8_OS_MACOSX | 7 #if V8_OS_MACOSX |
8 #include <mach/mach_time.h> | 8 #include <mach/mach_time.h> |
9 #endif | 9 #endif |
10 #if V8_OS_POSIX | 10 #if V8_OS_POSIX |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // change, we detect the minimum time between measurements. | 132 // change, we detect the minimum time between measurements. |
133 do { | 133 do { |
134 now = Now(); | 134 now = Now(); |
135 delta = now - start; | 135 delta = now - start; |
136 } while (now <= start); | 136 } while (now <= start); |
137 EXPECT_NE(static_cast<int64_t>(0), delta.InMicroseconds()); | 137 EXPECT_NE(static_cast<int64_t>(0), delta.InMicroseconds()); |
138 } while (delta > target_granularity && !timer.HasExpired(kExpirationTimeout)); | 138 } while (delta > target_granularity && !timer.HasExpired(kExpirationTimeout)); |
139 EXPECT_LE(delta, target_granularity); | 139 EXPECT_LE(delta, target_granularity); |
140 } | 140 } |
141 | 141 |
142 } | 142 } // namespace |
143 | 143 |
144 | 144 |
145 TEST(Time, NowResolution) { | 145 TEST(Time, NowResolution) { |
146 // We assume that Time::Now() has at least 16ms resolution. | 146 // We assume that Time::Now() has at least 16ms resolution. |
147 static const TimeDelta kTargetGranularity = TimeDelta::FromMilliseconds(16); | 147 static const TimeDelta kTargetGranularity = TimeDelta::FromMilliseconds(16); |
148 ResolutionTest<Time>(&Time::Now, kTargetGranularity); | 148 ResolutionTest<Time>(&Time::Now, kTargetGranularity); |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 TEST(TimeTicks, NowResolution) { | 152 TEST(TimeTicks, NowResolution) { |
(...skipping 24 matching lines...) Expand all Loading... |
177 EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0); | 177 EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0); |
178 EXPECT_GE(highres_ticks, previous_highres_ticks); | 178 EXPECT_GE(highres_ticks, previous_highres_ticks); |
179 EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0); | 179 EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0); |
180 previous_normal_ticks = normal_ticks; | 180 previous_normal_ticks = normal_ticks; |
181 previous_highres_ticks = highres_ticks; | 181 previous_highres_ticks = highres_ticks; |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 } // namespace base | 185 } // namespace base |
186 } // namespace v8 | 186 } // namespace v8 |
OLD | NEW |