Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Linux/tools/testing/selftests/bpf/benchs/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 1 kB image not shown  

Quelle  bench_count.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
#include "bench.h"

/* COUNT-GLOBAL benchmark */

static struct count_global_ctx {
 struct counter hits;
} count_global_ctx;

static void *count_global_producer(void *input)
{
 struct count_global_ctx *ctx = &count_global_ctx;

 while (true) {
  atomic_inc(&ctx->hits.value);
 }
 return NULL;
}

static void count_global_measure(struct bench_res *res)
{
 struct count_global_ctx *ctx = &count_global_ctx;

 res->hits = atomic_swap(&ctx->hits.value, 0);
}

/* COUNT-local benchmark */

static struct count_local_ctx {
 struct counter *hits;
} count_local_ctx;

static void count_local_setup(void)
{
 struct count_local_ctx *ctx = &count_local_ctx;

 ctx->hits = calloc(env.producer_cnt, sizeof(*ctx->hits));
 if (!ctx->hits)
  exit(1);
}

static void *count_local_producer(void *input)
{
 struct count_local_ctx *ctx = &count_local_ctx;
 int idx = (long)input;

 while (true) {
  atomic_inc(&ctx->hits[idx].value);
 }
 return NULL;
}

static void count_local_measure(struct bench_res *res)
{
 struct count_local_ctx *ctx = &count_local_ctx;
 int i;

 for (i = 0; i < env.producer_cnt; i++) {
  res->hits += atomic_swap(&ctx->hits[i].value, 0);
 }
}

const struct bench bench_count_global = {
 .name = "count-global",
 .producer_thread = count_global_producer,
 .measure = count_global_measure,
 .report_progress = hits_drops_report_progress,
 .report_final = hits_drops_report_final,
};

const struct bench bench_count_local = {
 .name = "count-local",
 .setup = count_local_setup,
 .producer_thread = count_local_producer,
 .measure = count_local_measure,
 .report_progress = hits_drops_report_progress,
 .report_final = hits_drops_report_final,
};

Messung V0.5
C=97 H=91 G=93

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.