Page 243 - ARM 64 Bit Assembly Language
P. 243
Integer mathematics 231
110
111 clock_t test(int size, char *name, bigint l[], bigint r[],
112 bigint (*bigint_op)(bigint l, bigint r), bigint op[]) {
113 bigint d;
114 clock_t stop, start = clock();
115 for (int i = 0; i < size; i++) {
116 d = bigint_op(l[i], r[i]);
117 if (bigint_ne(d, op[i]))
118 matherr(l[i], r[i], op[i], d, name);
119 bigint_free(d);
120 }
121 stop = clock();
122 printf("%s :\t %lf\n", name, (stop - start)/(double)CLOCKS_PER_SEC);
123 return (stop - start);
124 }
125
126 clock_t test_negate(int size, bigint l[], bigint op[]) {
127 char *name = "Neg";
128 bigint d;
129 clock_t stop, start = clock();
130 for (int i = 0; i < size; i++) {
131 d = bigint_negate(l[i]);
132 if (bigint_ne(d, op[i]))
133 matherr(l[i], l[i], op[i], d, name);
134 bigint_free(d);
135 }
136 stop = clock();
137 printf("%s :\t %lf\n", name, (stop - start)/(double)CLOCKS_PER_SEC);
138 return (stop - start);
139 }
140
141 clock_t test_cmp(int size, bigint l[], bigint r[], int op[]) {
142 char *name = "Cmp";
143 int d;
144 clock_t stop, start = clock();
145 bigint expected, actual;
146 for (int i = 0; i < size; i++) {
147 d = bigint_cmp(l[i], r[i]);
148 if (d != op[i]) {
149 actual = bigint_from_int(d);
150 expected = bigint_from_int(op[i]);
151 matherr(l[i], r[i], expected, actual, name);
152 }
153 }
154 stop = clock();
155 printf("%s :\t %lf\n", name, (stop - start)/(double)CLOCKS_PER_SEC);
156 return (stop - start);
157 }
158