Skip to content

@fredrik-johansson /gist:8198432
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
bsdnt exp(1) benchmark program
#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.