Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ttmath/ttmath.h"
- #include <ctime>
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #define DIGITS 200
- #define TESTS 100000
- #define TTMATH_MANTISSA_SIZE_BITS 1344
- // because 2^1344 = 3.839...e+404 (1344 = 21 * 64)
- // and we need more than 400 digits after comma
- // (multiplication needs at least DIGITS * 2 to store all the digits)
- char rand_digit()
- {
- return '0' + int(double(std::rand()) / RAND_MAX * 9.0);
- }
- void generate_something(std::string & out)
- {
- out.resize(DIGITS);
- for(size_t i=0 ; i<DIGITS ; ++i)
- out[i] = rand_digit();
- }
- int main()
- {
- std::srand(time(0));
- ttmath::Big<1, TTMATH_BITS(TTMATH_MANTISSA_SIZE_BITS)> a,b,c;
- int i, i2;
- std::string str_a, str_b;
- clock_t t1 = clock();
- for(i=0 ; i<10 ; ++i)
- {
- generate_something(str_a);
- generate_something(str_b);
- a = str_a;
- b = str_b;
- //std::cout << str_a << std::endl;
- //std::cout << str_b << std::endl;
- for(i2 = 0 ; i2<TESTS ; ++i2)
- c = a * b;
- }
- clock_t t2 = clock();
- std::cout << "time: " << (t2-t1) << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement