hurd: Enable x86_64 build script
[platform/upstream/glibc.git] / benchtests / bench-libmvec-skeleton.c
1 /* Skeleton for libmvec benchmark programs.
2    Copyright (C) 2021-2023 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18
19 #include <string.h>
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <time.h>
24 #include <inttypes.h>
25 #include <bench-timing.h>
26 #include <json-lib.h>
27 #include <bench-util.h>
28 #include <math-tests-arch.h>
29 #include <bench-libmvec-arch.h>
30
31 #include <bench-util.c>
32 #define D_ITERS 10000
33
34 int
35 main (int argc, char **argv)
36 {
37   unsigned long i, k;
38   timing_t start, end;
39   json_ctx_t json_ctx;
40
41 #ifdef INIT_ARCH
42   INIT_ARCH ();
43 #endif
44
45   bench_start ();
46
47 #ifdef BENCH_INIT
48   BENCH_INIT ();
49 #endif
50
51   json_init (&json_ctx, 2, stdout);
52
53   /* Begin function.  */
54   json_attr_object_begin (&json_ctx, FUNCNAME);
55
56   for (int v = 0; v < NUM_VARIANTS; v++)
57     {
58       double d_total_time = 0;
59       timing_t cur;
60       for (k = 0; k < D_ITERS; k++)
61         {
62           TIMING_NOW (start);
63           for (i = 0; i < NUM_SAMPLES (v); i++)
64             BENCH_FUNC (v, i);
65           TIMING_NOW (end);
66
67           TIMING_DIFF (cur, start, end);
68
69           TIMING_ACCUM (d_total_time, cur);
70         }
71       double d_total_data_set = D_ITERS * NUM_SAMPLES (v) * STRIDE;
72
73       /* Begin variant.  */
74       json_attr_object_begin (&json_ctx, VARIANT (v));
75
76       json_attr_double (&json_ctx, "duration", d_total_time);
77       json_attr_double (&json_ctx, "iterations", d_total_data_set);
78       json_attr_double (&json_ctx, "mean", d_total_time / d_total_data_set);
79
80       /* End variant.  */
81       json_attr_object_end (&json_ctx);
82     }
83
84   /* End function.  */
85   json_attr_object_end (&json_ctx);
86
87   return 0;
88 }