1 /*
2 mpn_mulmid-profile-main.c: program for profiling mpn middle products
3
4 Copyright (C) 2007, 2008, David Harvey
5
6 This file is part of the zn_poly library (version 0.9).
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) version 3 of the License.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 */
22
23
24 #include <string.h>
25 #include <math.h>
26 #include "support.h"
27 #include "profiler.h"
28 #include "zn_poly_internal.h"
29 #include "zn_poly.h"
30
31
32 /*
33 Performs and prints one line of profiling output, for the given
34 integer length
35 */
36 void
do_line(size_t n)37 do_line (size_t n)
38 {
39 profile_info_t info;
40
41 printf ("n = %5lu", n);
42 fflush (stdout);
43
44 double spread, result;
45
46 info->n1 = 2 * n - 1;
47 info->n2 = n;
48 result = profile (&spread, NULL, profile_mpn_smp_basecase,
49 &info, 1.0);
50 printf (", %.3le (%.1lf%%)", result, 100 * spread);
51
52 if (n >= 2)
53 {
54 info->n = n;
55 result = profile (&spread, NULL, profile_mpn_smp_kara,
56 &info, 1.0);
57 printf (", %.3le (%.1lf%%)", result, 100 * spread);
58 }
59 else
60 printf (", N/A ");
61
62 result = profile (&spread, NULL, profile_mpn_smp, &info, 1.0);
63 printf (", %.3le (%.1lf%%)", result, 100 * spread);
64
65 info->n1 = info->n2 = n;
66 result = profile (&spread, NULL, profile_mpn_mul, &info, 1.0);
67 printf (", %.3le (%.1lf%%)", result, 100 * spread);
68
69 info->n1 = 2 * n - 1;
70 info->n2 = n;
71 result = profile (&spread, NULL, profile_mpn_mulmid_fallback, &info, 1.0);
72 printf (", %.3le (%.1lf%%)", result, 100 * spread);
73
74 printf ("\n");
75 }
76
77
78 #if __cplusplus
79 extern "C"
80 #endif
81 void
prof_main(int argc,char * argv[])82 prof_main (int argc, char* argv[])
83 {
84 // read command line arguments
85
86 // if you do "length <nnn>" then only that length will be profiled
87 // otherwise it ranges over various lengths
88
89 int do_one_length = 0;
90 ulong chosen_length = 0;
91
92 int i;
93 for (i = 1; i < argc; i++)
94 {
95 if (!strcmp (argv[i], "length"))
96 {
97 do_one_length = 1;
98 chosen_length = atol (argv[++i]);
99 }
100 else
101 {
102 printf ("unknown option %s\n", argv[i]);
103 exit (1);
104 }
105 }
106
107 int j;
108 size_t n;
109
110 printf ("fields: smp_basecase, smp_kara, "
111 "smp, mpn_mul, mulmid_fallback\n");
112
113 if (do_one_length)
114 {
115 do_line (chosen_length);
116 }
117 else
118 {
119 // loop over lengths, spaced out logarithmically
120 for (n = 1; n <= 100; n++)
121 do_line (n);
122 }
123 }
124
125 // end of file ****************************************************************
126