本文整理汇总了C++中benchmark::State类的典型用法代码示例。如果您正苦于以下问题:C++ State类的具体用法?C++ State怎么用?C++ State使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BM_lookupEventTag_NOT
static void BM_lookupEventTag_NOT(benchmark::State& state) {
prechargeEventMap();
while (set.find(notTag) != set.end()) {
++notTag;
if (notTag >= USHRT_MAX) notTag = 1;
}
while (state.KeepRunning()) {
size_t len;
android_lookupEventTag_len(map, &len, notTag);
}
++notTag;
if (notTag >= USHRT_MAX) notTag = 1;
}
示例2: BM_AdeptJacobianReverse
static void BM_AdeptJacobianReverse(benchmark::State &state) {
while (state.KeepRunning()) {
double jac[9];
adept::adouble vector[3];
adept::set_values(vector, 3, g_vector);
adept::adouble bivector[3];
adept::set_values(bivector, 3, g_bivector);
g_stack.new_recording();
adept::adouble vec_ip_biv[3] = {0.0, 0.0, 0.0};
InnerProductVectorBivector(vector, bivector, vec_ip_biv);
g_stack.independent(vector, 3);
g_stack.dependent(vec_ip_biv, 3);
g_stack.jacobian_reverse(jac);
}
}
示例3: BM_lexer
static void BM_lexer(benchmark::State& state)
{
while (state.KeepRunning())
{
std::ifstream fin("benchmarks/test.sexp");
if (!fin)
{
throw std::runtime_error("failed to open benchmarks/test.sexp");
}
else
{
sexp::Lexer lexer(fin);
while(lexer.getNextToken() != sexp::Lexer::TOKEN_EOF);
}
}
}
示例4: Iterate_all_files
static void Iterate_all_files(benchmark::State& state) {
std::unique_ptr<TemporaryFile> temp_file(CreateZip());
ZipArchiveHandle handle;
void* iteration_cookie;
ZipEntry data;
ZipString name;
while (state.KeepRunning()) {
OpenArchive(temp_file->path, &handle);
StartIteration(handle, &iteration_cookie);
while (Next(iteration_cookie, &data, &name) == 0) {
}
EndIteration(iteration_cookie);
CloseArchive(handle);
}
}
示例5: FindEntry_no_match
static void FindEntry_no_match(benchmark::State& state) {
// Create a temporary zip archive.
std::unique_ptr<TemporaryFile> temp_file(CreateZip());
ZipArchiveHandle handle;
ZipEntry data;
// In order to walk through all file names in the archive, look for a name
// that does not exist in the archive.
std::string_view name("thisFileNameDoesNotExist");
// Start the benchmark.
while (state.KeepRunning()) {
OpenArchive(temp_file->path, &handle);
FindEntry(handle, name, &data);
CloseArchive(handle);
}
}
示例6: DuplicateInputs
static void DuplicateInputs(benchmark::State& state)
{
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
const CChainParams& chainparams = Params();
CBlock block{};
CMutableTransaction coinbaseTx{};
CMutableTransaction naughtyTx{};
CBlockIndex* pindexPrev = ::ChainActive().Tip();
assert(pindexPrev != nullptr);
block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus());
block.nNonce = 0;
auto nHeight = pindexPrev->nHeight + 1;
// Make a coinbase TX
coinbaseTx.vin.resize(1);
coinbaseTx.vin[0].prevout.SetNull();
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = SCRIPT_PUB;
coinbaseTx.vout[0].nValue = GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
naughtyTx.vout.resize(1);
naughtyTx.vout[0].nValue = 0;
naughtyTx.vout[0].scriptPubKey = SCRIPT_PUB;
uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100;
for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
naughtyTx.vin.emplace_back(GetRandHash(), 0, CScript(), 0);
}
naughtyTx.vin.emplace_back(naughtyTx.vin.back());
block.vtx.push_back(MakeTransactionRef(std::move(coinbaseTx)));
block.vtx.push_back(MakeTransactionRef(std::move(naughtyTx)));
block.hashMerkleRoot = BlockMerkleRoot(block);
while (state.KeepRunning()) {
CValidationState cvstate{};
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), false, false));
assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate");
}
}
示例7: BENCHMARK_F
BENCHMARK_F( Tcp4Fixture, AddEntryToTcp4Target )( benchmark::State& state ) {
char buffer[1024];
for(auto _ : state){
if( stumpless_add_entry( target, entry ) <= 0 ) {
state.SkipWithError( "could not send an entry to the tcp target" );
}
recv_from_handle( accepted, buffer, 1024 );
}
state.counters["CallsToAlloc"] = ( double ) tcp4_memory_counter.malloc_count;
state.counters["MemoryAllocated"] = ( double ) tcp4_memory_counter.alloc_total;
state.counters["CallsToRealloc"] = ( double ) tcp4_memory_counter.realloc_count;
state.counters["CallsToFree"] = ( double ) tcp4_memory_counter.free_count;
state.counters["MemoryFreed"] = ( double ) tcp4_memory_counter.free_total;
}
示例8: DATABASE_store_append
static void DATABASE_store_append(benchmark::State& state) {
// Serialize the example result set into a string.
std::string content;
auto qd = getExampleQueryData(20, 100);
serializeQueryDataJSON(qd, content);
size_t k = 0;
while (state.KeepRunning()) {
setDatabaseValue(kPersistentSettings, "key" + std::to_string(k), content);
deleteDatabaseValue(kPersistentSettings, "key" + std::to_string(k));
k++;
}
// All benchmarks will share a single database handle.
for (size_t i = 0; i < k; ++i) {
// deleteDatabaseValue(kPersistentSettings, "key" + std::to_string(i));
}
}
示例9: BnBExhaustion
static void BnBExhaustion(benchmark::State& state)
{
// Setup
std::vector<OutputGroup> utxo_pool;
CoinSet selection;
CAmount value_ret = 0;
CAmount not_input_fees = 0;
while (state.KeepRunning()) {
// Benchmark
CAmount target = make_hard_case(17, utxo_pool);
SelectCoinsBnB(utxo_pool, target, 0, selection, value_ret, not_input_fees); // Should exhaust
// Cleanup
utxo_pool.clear();
selection.clear();
}
}
示例10: BM_WindowsCriticalSection
static void BM_WindowsCriticalSection(benchmark::State& state)
{
if (state.thread_index == 0)
{
InitializeCriticalSection(&CriticalSection);
}
while (state.KeepRunning())
{
EnterCriticalSection(&CriticalSection);
LeaveCriticalSection(&CriticalSection);
}
if (state.thread_index == 0)
{
DeleteCriticalSection(&CriticalSection);
}
}
示例11: bm
[[gnu::noinline]]
void bm(benchmark::State& state, D d){
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution< T > dis(
std::numeric_limits< T >::min(),
std::numeric_limits< T >::max()
);
auto m = make_matrix_fn(d, [&dis, &gen](auto, auto){
return dis(gen);
}, maker::heap_t());
while(state.KeepRunning()){
auto res = sobel_x< T >(m);
benchmark::DoNotOptimize(res);
}
}
示例12: DeserializeAndCheckBlockTest
static void DeserializeAndCheckBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)block_bench::block413567,
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
SER_NETWORK, PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
while (state.KeepRunning()) {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block413567)));
CValidationState validationState;
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
}
}
示例13: BM_sobel
[[gnu::noinline]]
void BM_sobel(benchmark::State& state, D d){
using value_type = InputType;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution< value_type > dis(
std::numeric_limits< value_type >::min(),
std::numeric_limits< value_type >::max()
);
auto m = make_matrix_fn(d, [&dis, &gen](auto, auto){
return dis(gen);
});
while(state.KeepRunning()){
auto res = sobel_x< ResultType >(m);
}
}
示例14: BENCH_Dart_count_multi_threaded
static void BENCH_Dart_count_multi_threaded(benchmark::State& state)
{
while (state.KeepRunning())
{
uint32 nb_darts_2 = 0u;
std::vector<uint32> nb_darts_per_thread(cgogn::nb_threads() + 2);
for (auto& n : nb_darts_per_thread)
n = 0u;
nb_darts_2 = 0u;
bench_map.parallel_foreach_dart([&nb_darts_per_thread] (cgogn::Dart, uint32 thread_index)
{
nb_darts_per_thread[thread_index]++;
});
for (uint32 n : nb_darts_per_thread)
nb_darts_2 += n;
cgogn_assert(nb_darts_2 == bench_map.nb_darts());
}
}
示例15: RollingBloom
static void RollingBloom(benchmark::State& state)
{
CRollingBloomFilter filter(120000, 0.000001);
std::vector<unsigned char> data(32);
uint32_t count = 0;
uint64_t match = 0;
while (state.KeepRunning()) {
count++;
data[0] = count;
data[1] = count >> 8;
data[2] = count >> 16;
data[3] = count >> 24;
filter.insert(data);
data[0] = count >> 24;
data[1] = count >> 16;
data[2] = count >> 8;
data[3] = count;
match += filter.contains(data);
}
}