2 * Test whether to include squaring code given the current settings
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
19 * The Initial Developer of the Original Code is
20 * Michael J. Fromberger.
21 * Portions created by the Initial Developer are Copyright (C) 1997
22 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
45 #define MP_SQUARE 1 /* make sure squaring code is included */
50 int main(int argc
, char *argv
[])
55 double multime
, sqrtime
;
58 seed
= (unsigned int)time(NULL
);
61 fprintf(stderr
, "Usage: %s <ntests> <nbits>\n", argv
[0]);
65 if((ntests
= abs(atoi(argv
[1]))) == 0) {
66 fprintf(stderr
, "%s: must request at least 1 test.\n", argv
[0]);
69 if((prec
= abs(atoi(argv
[2]))) < CHAR_BIT
) {
70 fprintf(stderr
, "%s: must request at least %d bits.\n", argv
[0],
75 prec
= (prec
+ (DIGIT_BIT
- 1)) / DIGIT_BIT
;
77 mp_init_size(&a
, prec
);
78 mp_init_size(&c
, 2 * prec
);
80 /* Test multiplication by self */
83 for(ix
= 0; ix
< ntests
; ix
++) {
84 mpp_random_size(&a
, prec
);
89 multime
= (double)(stop
- start
) / CLOCKS_PER_SEC
;
94 for(ix
= 0; ix
< ntests
; ix
++) {
95 mpp_random_size(&a
, prec
);
100 sqrtime
= (double)(stop
- start
) / CLOCKS_PER_SEC
;
102 printf("Multiply: %.4f\n", multime
);
103 printf("Square: %.4f\n", sqrtime
);
104 if(multime
< sqrtime
) {
105 printf("Speedup: %.1f%%\n", 100.0 * (1.0 - multime
/ sqrtime
));
106 printf("Prefer: multiply\n");
108 printf("Speedup: %.1f%%\n", 100.0 * (1.0 - sqrtime
/ multime
));
109 printf("Prefer: square\n");
112 mp_clear(&a
); mp_clear(&c
);