Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

bsdnt exp(1) benchmark program

View gist:8198432
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "nn.h"
#include "test.h"
#include "zz.h"
 
void
zz_bsplit(zz_t p, zz_t q, ulong a, ulong b)
{
if (b - a == 1)
{
zz_seti(p, 1);
zz_seti(q, b);
}
else
{
ulong m;
 
zz_t p1, q2;
 
zz_init(p1);
zz_init(q2);
 
m = a + (b - a) / 2;
 
zz_bsplit(p1, q, a, m);
zz_bsplit(p, q2, m, b);
 
zz_mul(p1, p1, q2);
zz_add(p, p, p1);
 
zz_mul(q, q, q2);
 
zz_clear(p1);
zz_clear(q2);
}
}
 
void zz_e(zz_t y, ulong prec)
{
ulong N;
zz_t p, q;
 
N = 1.1 * prec / log(prec) + 20;
 
zz_init(p);
zz_init(q);
 
zz_bsplit(p, q, 0, N);
 
zz_add(p, p, q);
zz_mul_2exp(p, p, prec);
zz_div(y, p, q);
 
zz_clear(p);
zz_clear(q);
}
 
void time_e(void)
{
ulong digits, prec, count, iter;
clock_t t;
 
zz_t y;
zz_init(y);
 
zz_e(y, 333);
zz_print(y);
 
printf("\n");
 
for (digits = 100; digits <= 10000000; digits *= 10)
{
prec = digits * 3.333;
 
printf("digits = %lu: ", digits);
fflush(stdout);
 
iter = 1;
if (digits == 100) iter = 100000;
if (digits == 1000) iter = 10000;
if (digits == 10000) iter = 100;
if (digits == 100000) iter = 10;
if (digits == 1000000) iter = 1;
 
t = clock();
for (count = 0; count < iter; count++)
zz_e(y, prec);
t = clock() - t;
 
printf("%g s\n", ((double) t) / CLOCKS_PER_SEC / iter);
 
}
 
zz_clear(y);
}
 
int main(void)
{
time_e();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.