po: Incorporate translations
[glibc.git] / benchtests / bench-fclose.c
blob29233f9db371f349d40c8fffc4b64e61367db9e5
1 /* Benchmark fclose.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include "bench-timing.h"
24 #include "json-lib.h"
26 #define NUM_FILES 1000000
27 #define NUM_FCLOSE 100
29 int
30 main (int argc, char **argv)
32 json_ctx_t json_ctx;
33 json_init (&json_ctx, 0, stdout);
34 json_document_begin (&json_ctx);
36 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
37 json_attr_object_begin (&json_ctx, "functions");
38 json_attr_object_begin (&json_ctx, "fclose");
40 FILE *ff, *keep[NUM_FCLOSE];
41 int i;
43 for (i = 0; i < NUM_FILES; i++)
45 ff = fdopen (STDIN_FILENO, "r");
46 if (!ff)
48 fprintf (stderr, "### failed to fdopen: %m\n");
49 return EXIT_FAILURE;
51 if (i < NUM_FCLOSE)
52 keep[i] = ff;
55 timing_t start, stop, elapsed;
57 TIMING_NOW (start);
59 for (i = 0; i < NUM_FCLOSE; i++)
60 fclose (keep[i]);
62 TIMING_NOW (stop);
64 TIMING_DIFF (elapsed, start, stop);
66 json_attr_uint (&json_ctx, "number of FILEs", NUM_FILES);
67 json_attr_uint (&json_ctx, "number of fclose calls", NUM_FCLOSE);
68 json_attr_uint (&json_ctx, "duration", elapsed);
70 json_attr_object_end (&json_ctx);
71 json_attr_object_end (&json_ctx);
72 json_document_end (&json_ctx);
74 return 0;