cppgc: Fix empty benchmark on Windows

Keep idiomatic state loop but rely on USE() to avoid
warning about unused variables.

Bug: v8:11687
Change-Id: Icde295723c5d389d827280f70a65776866d4e7a9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2850645
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74200}
This commit is contained in:
Michael Lippautz 2021-04-26 12:32:05 +02:00 committed by Commit Bot
parent e250cc167c
commit 707c5a0b38
7 changed files with 17 additions and 5 deletions

View File

@ -9,7 +9,7 @@ group("gn_all") {
deps = []
if (v8_enable_google_benchmark && !is_win) {
if (v8_enable_google_benchmark) {
deps += [
":empty_benchmark",
"cppgc:gn_all",
@ -17,7 +17,7 @@ group("gn_all") {
}
}
if (v8_enable_google_benchmark && !is_win) {
if (v8_enable_google_benchmark) {
v8_executable("empty_benchmark") {
testonly = true

View File

@ -1,3 +1,4 @@
include_rules = [
"+src/base",
"+third_party/google_benchmark/src/include/benchmark/benchmark.h",
]

View File

@ -9,12 +9,12 @@ group("gn_all") {
deps = []
if (v8_enable_google_benchmark && !is_win) {
if (v8_enable_google_benchmark) {
deps += [ ":cppgc_basic_benchmarks" ]
}
}
if (v8_enable_google_benchmark && !is_win) {
if (v8_enable_google_benchmark) {
v8_source_set("cppgc_benchmark_support") {
testonly = true

View File

@ -1,5 +1,6 @@
include_rules = [
"+include/cppgc",
"+src/base",
"+src/heap/cppgc",
"+test/unittests/heap/cppgc",
"+third_party/google_benchmark/src/include/benchmark/benchmark.h",

View File

@ -5,6 +5,7 @@
#include "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/heap-consistency.h"
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/utils.h"
@ -24,6 +25,7 @@ class TinyObject final : public cppgc::GarbageCollected<TinyObject> {
BENCHMARK_F(Allocate, Tiny)(benchmark::State& st) {
subtle::NoGarbageCollectionScope no_gc(*Heap::From(&heap()));
for (auto _ : st) {
USE(_);
benchmark::DoNotOptimize(
cppgc::MakeGarbageCollected<TinyObject>(heap().GetAllocationHandle()));
}
@ -39,6 +41,7 @@ class LargeObject final : public GarbageCollected<LargeObject> {
BENCHMARK_F(Allocate, Large)(benchmark::State& st) {
subtle::NoGarbageCollectionScope no_gc(*Heap::From(&heap()));
for (auto _ : st) {
USE(_);
benchmark::DoNotOptimize(
cppgc::MakeGarbageCollected<LargeObject>(heap().GetAllocationHandle()));
}

View File

@ -5,6 +5,7 @@
#include "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/persistent.h"
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/utils.h"
@ -65,6 +66,7 @@ BENCHMARK_F(Trace, Static)(benchmark::State& st) {
heap().GetAllocationHandle())));
VisitorBase visitor;
for (auto _ : st) {
USE(_);
DispatchTrace(&visitor, holder->base_ref);
}
}
@ -75,6 +77,7 @@ BENCHMARK_F(Trace, Dynamic)(benchmark::State& st) {
heap().GetAllocationHandle())));
VisitorBase visitor;
for (auto _ : st) {
USE(_);
DispatchTrace(&visitor, holder->mixin_ref);
}
}

View File

@ -2,11 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/macros.h"
#include "third_party/google_benchmark/src/include/benchmark/benchmark.h"
static void BM_Empty(benchmark::State& state) {
for (auto _ : state) {
USE(_);
}
}
// Register the function as a benchmark
// Register the function as a benchmark. The empty benchmark ensures that the
// framework compiles and links as expected.
BENCHMARK(BM_Empty);