42 lines · cpp
1//===-- Benchmark function -----------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "LibcBenchmark.h"10#include "llvm/ADT/StringRef.h"11#include "llvm/TargetParser/Host.h"12 13namespace llvm {14namespace libc_benchmarks {15 16void checkRequirements() {17 const auto &CpuInfo = benchmark::CPUInfo::Get();18 if (CpuInfo.scaling == benchmark::CPUInfo::ENABLED)19 report_fatal_error(20 "CPU scaling is enabled, the benchmark real time measurements may be "21 "noisy and will incur extra overhead.");22}23 24HostState HostState::get() {25 const auto &CpuInfo = benchmark::CPUInfo::Get();26 HostState H;27 H.CpuFrequency = CpuInfo.cycles_per_second;28 H.CpuName = llvm::sys::getHostCPUName().str();29 for (const auto &BenchmarkCacheInfo : CpuInfo.caches) {30 CacheInfo CI;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));36 }37 return H;38}39 40} // namespace libc_benchmarks41} // namespace llvm42