forked from cmuparlay/parlaylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigint_add.cpp
43 lines (37 loc) · 1.11 KB
/
bigint_add.cpp
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
#include <iostream>
#include <string>
#include <random>
#include <limits>
#include <parlay/primitives.h>
#include <parlay/random.h>
#include "bigint_add.h"
// **************************************************************
// Driver code
// **************************************************************
int main(int argc, char* argv[]) {
auto usage = "Usage: bigint_add <size>";
if (argc != 2) std::cout << usage << std::endl;
else {
long n;
try { n = std::stol(argv[1]); }
catch (...) { std::cout << usage << std::endl; return 1; }
auto rand_num = [] (long m, long seed) {
parlay::random_generator gen(seed);
auto maxv = std::numeric_limits<digit>::max();
std::uniform_int_distribution<digit> dis(0, maxv);
return parlay::tabulate(m, [&] (long i) {
auto r = gen[i];
return dis(r);});
};
long m = n/digit_len;
bigint a = rand_num(m, 0);
bigint b = rand_num(m, 1);
bigint result;
parlay::internal::timer t("Time");
for (int i=0; i < 5; i++) {
result = add(a, b);
t.next("bigint_add");
}
std::cout << n << " bits" << std::endl;
}
}