1 //===-- Benchmark function -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "LibcBenchmark.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/TargetParser/Host.h"
14 namespace libc_benchmarks
{
16 void checkRequirements() {
17 const auto &CpuInfo
= benchmark::CPUInfo::Get();
18 if (CpuInfo
.scaling
== benchmark::CPUInfo::ENABLED
)
20 "CPU scaling is enabled, the benchmark real time measurements may be "
21 "noisy and will incur extra overhead.");
24 HostState
HostState::get() {
25 const auto &CpuInfo
= benchmark::CPUInfo::Get();
27 H
.CpuFrequency
= CpuInfo
.cycles_per_second
;
28 H
.CpuName
= llvm::sys::getHostCPUName().str();
29 for (const auto &BenchmarkCacheInfo
: CpuInfo
.caches
) {
31 CI
.Type
= BenchmarkCacheInfo
.type
;
32 CI
.Level
= BenchmarkCacheInfo
.level
;
33 CI
.Size
= BenchmarkCacheInfo
.size
;
34 CI
.NumSharing
= BenchmarkCacheInfo
.num_sharing
;
35 H
.Caches
.push_back(std::move(CI
));
40 } // namespace libc_benchmarks