Introduction
Introduction Statistics Contact Development Disclaimer Help
benchmark.c - libzahl - big integer library
git clone git://git.suckless.org/libzahl
Log
Files
Refs
README
LICENSE
---
benchmark.c (3504B)
---
1 #include "util.h"
2
3
4 #define BENCHMARK(INSTRUCTION, FAST)\
5 do {\
6 i = FAST ? 1000000L : 1000L;\
7 TIC;\
8 while (i--) {\
9 (void)INSTRUCTION;\
10 }\
11 TOC;\
12 printf("%s: %s %s (152 bits)\n",\
13 #INSTRUCTION, STIME, FAST ? "µs" : "ms");\
14 } while (0)
15
16
17 int
18 main(int argc, char *argv[])
19 {
20 char buf[2000];
21 z_t a, b, c, d, tiny;
22 jmp_buf jmp;
23 size_t i;
24
25 benchmark_init();
26
27 if (setjmp(jmp)) {
28 zperror(argv[0]);
29 return 1;
30 }
31 zsetup(jmp);
32 zinit(a);
33 zinit(b);
34 zinit(c);
35 zinit(d);
36 zinit(tiny);
37
38 zsets(a, "5495468234592964023447280368442884381000481887");
39 zsets(b, "4781084818570683458641843084358135840548636081");
40 zsets(tiny, "5");
41
42 BENCHMARK(zset(c, a), 1);
43 BENCHMARK(zseti(c, 1000000000LL), 1);
44 BENCHMARK(zsetu(c, 1000000000ULL), 1);
45 BENCHMARK(zneg(c, a), 1);
46 BENCHMARK(zneg(a, a), 1);
47 BENCHMARK(zabs(c, a), 1);
48 BENCHMARK(zabs(a, a), 1);
49 BENCHMARK(zadd_unsigned(c, a, b), 1);
50 BENCHMARK(zsub_unsigned(c, a, b), 1);
51 BENCHMARK(zadd(c, a, b), 1);
52 BENCHMARK(zsub(c, a, b), 1);
53 BENCHMARK(zand(c, a, b), 1);
54 BENCHMARK(zor(c, a, b), 1);
55 BENCHMARK(zxor(c, a, b), 1);
56 BENCHMARK(znot(c, a), 1);
57 BENCHMARK(zeven(a), 1);
58 BENCHMARK(zodd(a), 1);
59 BENCHMARK(zeven_nonzero(a), 1);
60 BENCHMARK(zodd_nonzero(a), 1);
61 BENCHMARK(zzero(a), 1);
62 BENCHMARK(zsignum(a), 1);
63 BENCHMARK(zbits(a), 1);
64 BENCHMARK(zlsb(a), 1);
65 BENCHMARK(zswap(a, b), 1);
66 BENCHMARK(zlsh(c, a, 76), 1);
67 BENCHMARK(zrsh(c, a, 76), 1);
68 BENCHMARK(ztrunc(c, a, 76), 1);
69 BENCHMARK(ztrunc(c, c, 76), 1);
70 BENCHMARK(zsplit(c, d, a, 76), 1);
71 BENCHMARK(zcmpmag(a, b), 1);
72 BENCHMARK(zcmp(a, b), 1);
73 BENCHMARK(zcmpi(a, 1000000000LL), 1);
74 BENCHMARK(zcmpi(a, -1000000000LL), 1);
75 BENCHMARK(zcmpu(a, 1000000000ULL), 1);
76 BENCHMARK(zbset(c, a, 76, 1), 1);
77 BENCHMARK(zbset(a, a, 76, 1), 1);
78 BENCHMARK(zbset(c, a, 76, 0), 1);
79 BENCHMARK(zbset(c, c, 76, 0), 1);
80 BENCHMARK(zbset(c, a, 76, -1), 1);
81 BENCHMARK(zbset(a, a, 76, -1), 1);
82 BENCHMARK(zbtest(a, 76), 1);
83 #ifndef HEBIMATH /* These take too long in hebimath because of inefficie…
84 BENCHMARK(zgcd(c, a, b), 0);
85 #endif
86 BENCHMARK(zmul(c, a, b), 0);
87 BENCHMARK(zmul(c, a, a), 0);
88 BENCHMARK(zsqr(c, a), 0);
89 #ifndef HEBIMATH /* Ditto. */
90 zsets(d, "1484298084218938358480511181388394862858002249");
91 BENCHMARK(zmodmul(c, a, b, d), 0);
92 BENCHMARK(zmodmul(c, a, a, d), 0);
93 BENCHMARK(zmodsqr(c, a, d), 0);
94 BENCHMARK(zmodmul(c, a, b, tiny), 0);
95 BENCHMARK(zmodmul(c, a, a, tiny), 0);
96 BENCHMARK(zmodsqr(c, a, tiny), 0);
97 zsets(d, "12");
98 BENCHMARK(zpow(c, a, d), 0); /* Memory corruption when using h…
99 BENCHMARK(zpowu(c, a, 12), 0); /* Memory corruption when using h…
100 BENCHMARK(zmodpow(c, a, d, b), 0);
101 BENCHMARK(zmodpowu(c, a, 12, b), 0);
102 #endif
103 BENCHMARK(zsets(c, "54954682345929640234472803684428843810004818…
104 BENCHMARK(zstr_length(a, 10), 0);
105 BENCHMARK(zstr(a, buf, 0), 0);
106 BENCHMARK(zstr(a, buf, sizeof(buf) - 1), 0);
107 BENCHMARK(zrand(c, DEFAULT_RANDOM, QUASIUNIFORM, a), 0);
108 BENCHMARK(zrand(c, DEFAULT_RANDOM, UNIFORM, a), 0);
109 BENCHMARK(zrand(c, DEFAULT_RANDOM, MODUNIFORM, a), 0);
110 BENCHMARK(zptest(d, a, 5), 0);
111 BENCHMARK(zsave(a, buf), 1);
112 BENCHMARK(zload(a, buf), 1);
113 BENCHMARK(zdiv(c, a, b), 1);
114 BENCHMARK(zmod(c, a, b), 1);
115 BENCHMARK(zdivmod(c, d, a, b), 1);
116 #ifndef HEBIMATH /* Ditto. */
117 BENCHMARK(zdiv(c, a, tiny), 0);
118 BENCHMARK(zmod(c, a, tiny), 0);
119 BENCHMARK(zdivmod(c, d, a, tiny), 0);
120 #endif
121
122 zfree(a);
123 zfree(b);
124 zfree(c);
125 zfree(d);
126 zfree(tiny);
127 zunsetup();
128 return 0;
129 (void) argc;
130 }
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.