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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-gc-tracer.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/heap/gc-tracer-unittest.cc
diff --git a/test/unittests/heap/gc-tracer-unittest.cc b/test/unittests/heap/gc-tracer-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b57d4a6e2453e6018fdbbc570c98e148caaa99d2
--- /dev/null
+++ b/test/unittests/heap/gc-tracer-unittest.cc
@@ -0,0 +1,49 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <cmath>
+#include <limits>
+
+#include "src/heap/gc-tracer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+TEST(GCTracer, AverageSpeed) {
+ RingBuffer<BytesAndDuration> buffer;
+ EXPECT_EQ(100 / 2,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 0));
+ buffer.Push(MakeBytesAndDuration(100, 8));
+ EXPECT_EQ(100 / 2,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 2));
+ EXPECT_EQ(200 / 10,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 3));
+ const int max_speed = 1024 * MB;
+ buffer.Reset();
+ buffer.Push(MakeBytesAndDuration(max_speed, 0.5));
+ EXPECT_EQ(max_speed,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 1));
+ const int min_speed = 1;
+ buffer.Reset();
+ buffer.Push(MakeBytesAndDuration(1, 10000));
+ EXPECT_EQ(min_speed,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 1));
+ buffer.Reset();
+ int sum = 0;
+ for (int i = 0; i < buffer.kSize; i++) {
+ sum += i + 1;
+ buffer.Push(MakeBytesAndDuration(i + 1, 1));
+ }
+ EXPECT_EQ(
+ static_cast<int>(sum * 1.0 / buffer.kSize + 0.5),
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), buffer.kSize));
+ buffer.Push(MakeBytesAndDuration(100, 1));
+ EXPECT_EQ(
+ static_cast<int>((sum * 1.0 - 1 + 100) / buffer.kSize + 0.5),
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), buffer.kSize));
+}
+
+} // namespace internal
+} // namespace v8
« 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