1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Sebastian Pancratz
Copyright (C) 2013 Mike Hansen
******************************************************************************/
/*
Demo FLINT program to demonstrate some use of the fq_poly module.
*/
#include <time.h>
#include "fq_poly.h"
int main(void)
{
fmpz_t p;
long d, i;
fq_ctx_t ctx;
clock_t c0, c1;
double c;
fq_poly_t f, g, h;
FLINT_TEST_INIT(state);
fq_poly_init(f, ctx);
fq_poly_init(g, ctx);
fq_poly_init(h, ctx);
printf("Polynomial multiplication over GF(q)\n");
printf("------------------------------------\n");
{
printf("1) Two length-10,000 polynomials over GF(3^2)\n");
fmpz_init_set_ui(p, 3);
d = 2;
fq_ctx_init_conway(ctx, p, d, "X");
fq_poly_randtest(g, state, 10000, ctx);
fq_poly_randtest(h, state, 10000, ctx);
c0 = clock();
fq_poly_mul_classical(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("Classical: %fs\n", c);
c0 = clock();
for (i = 0; i < 100; i++)
fq_poly_mul_reorder(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("Reorder: %fms\n", 10 * c);
c0 = clock();
for (i = 0; i < 100; i++)
fq_poly_mul_KS(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("KS: %fms\n", 10 * c);
fq_ctx_clear(ctx);
fmpz_clear(p);
}
{
printf("2) Two length-500 polynomials over GF(3^263)\n");
fmpz_init_set_ui(p, 3);
d = 263;
fq_ctx_init_conway(ctx, p, d, "X");
fq_poly_randtest(g, state, 500, ctx);
fq_poly_randtest(h, state, 500, ctx);
c0 = clock();
fq_poly_mul_classical(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("Classical: %fs\n", c);
c0 = clock();
fq_poly_mul_reorder(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("Reorder: %fs\n", c);
c0 = clock();
for (i = 0; i < 100; i++)
fq_poly_mul_KS(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("KS: %fms\n", 10 * c);
fq_ctx_clear(ctx);
fmpz_clear(p);
}
{
printf("3) Two length-5 polynomials over GF(109987^4)\n");
fmpz_init_set_ui(p, 109987);
d = 4;
fq_ctx_init_conway(ctx, p, d, "X");
fq_poly_randtest(g, state, 4, ctx);
fq_poly_randtest(h, state, 4, ctx);
c0 = clock();
for (i = 0; i < 1000 * 100; i++)
fq_poly_mul_classical(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("Classical: %f\xb5s\n", 10 * c);
c0 = clock();
for (i = 0; i < 1000 * 100; i++)
fq_poly_mul_reorder(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("Reorder: %f\xb5s\n", 10 * c);
c0 = clock();
for (i = 0; i < 1000 * 100; i++)
fq_poly_mul_KS(f, g, h, ctx);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
printf("KS: %f\xb5s\n", 10 * c);
fq_ctx_clear(ctx);
fmpz_clear(p);
}
fq_poly_clear(f, ctx);
fq_poly_clear(g, ctx);
fq_poly_clear(h, ctx);
FLINT_TEST_CLEANUP(state);
return EXIT_SUCCESS;
}
|