v8/test/unittests/heap/index-generator-unittest.cc
Etienne Pierre-doray 0d813976ea [Heap]: Implement IndexGenerator for Jobs use cases.
Dynamic index generation used as starting seend boosts performance for
Jobs that have many work items. This is taken from
https://source.chromium.org/chromium/chromium/src/+/master:base/task/job_perftest.cc;l=30?q=job_perftest&ss=chromium

Change-Id: Ie1ba432808f07498f90ab4c0af419b8f9b72e342
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405799
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69854}
2020-09-11 19:25:33 +00:00

51 lines
1.2 KiB
C++

// Copyright 2020 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 "src/heap/index-generator.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
TEST(IndexGeneratorTest, Empty) {
IndexGenerator gen(0);
EXPECT_EQ(base::nullopt, gen.GetNext());
}
TEST(IndexGeneratorTest, GetNext) {
IndexGenerator gen(11);
EXPECT_EQ(0U, gen.GetNext());
EXPECT_EQ(5U, gen.GetNext());
EXPECT_EQ(2U, gen.GetNext());
EXPECT_EQ(8U, gen.GetNext());
EXPECT_EQ(1U, gen.GetNext());
EXPECT_EQ(3U, gen.GetNext());
EXPECT_EQ(6U, gen.GetNext());
EXPECT_EQ(9U, gen.GetNext());
EXPECT_EQ(4U, gen.GetNext());
EXPECT_EQ(7U, gen.GetNext());
EXPECT_EQ(10U, gen.GetNext());
EXPECT_EQ(base::nullopt, gen.GetNext());
}
TEST(IndexGeneratorTest, GiveBack) {
IndexGenerator gen(4);
EXPECT_EQ(0U, gen.GetNext());
EXPECT_EQ(2U, gen.GetNext());
EXPECT_EQ(1U, gen.GetNext());
gen.GiveBack(2);
gen.GiveBack(0);
EXPECT_EQ(0U, gen.GetNext());
EXPECT_EQ(2U, gen.GetNext());
EXPECT_EQ(3U, gen.GetNext());
EXPECT_EQ(base::nullopt, gen.GetNext());
}
} // namespace internal
} // namespace v8