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: test/unittests/heap/gc-tracer-unittest.cc

Issue 1830723004: Refactor the ring buffer in GCTracer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix cast Created 4 years, 8 months 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 | « test/cctest/test-gc-tracer.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <cmath>
6 #include <limits>
7
8 #include "src/heap/gc-tracer.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace v8 {
12 namespace internal {
13
14 TEST(GCTracer, AverageSpeed) {
15 RingBuffer<BytesAndDuration> buffer;
16 EXPECT_EQ(100 / 2,
17 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 0));
18 buffer.Push(MakeBytesAndDuration(100, 8));
19 EXPECT_EQ(100 / 2,
20 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 2));
21 EXPECT_EQ(200 / 10,
22 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 3));
23 const int max_speed = 1024 * MB;
24 buffer.Reset();
25 buffer.Push(MakeBytesAndDuration(max_speed, 0.5));
26 EXPECT_EQ(max_speed,
27 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 1));
28 const int min_speed = 1;
29 buffer.Reset();
30 buffer.Push(MakeBytesAndDuration(1, 10000));
31 EXPECT_EQ(min_speed,
32 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 1));
33 buffer.Reset();
34 int sum = 0;
35 for (int i = 0; i < buffer.kSize; i++) {
36 sum += i + 1;
37 buffer.Push(MakeBytesAndDuration(i + 1, 1));
38 }
39 EXPECT_EQ(
40 static_cast<int>(sum * 1.0 / buffer.kSize + 0.5),
41 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), buffer.kSize));
42 buffer.Push(MakeBytesAndDuration(100, 1));
43 EXPECT_EQ(
44 static_cast<int>((sum * 1.0 - 1 + 100) / buffer.kSize + 0.5),
45 GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), buffer.kSize));
46 }
47
48 } // namespace internal
49 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-gc-tracer.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698