Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rwst
Created November 16, 2015 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwst/ebacc780c7c879f9b739 to your computer and use it in GitHub Desktop.
Save rwst/ebacc780c7c879f9b739 to your computer and use it in GitHub Desktop.
benchmark program, compile with g++ -O0 -std=c++11 piranha-degree.cpp -lgmp -lmpfr -lpthread
#define BENCHPRESS_CONFIG_MAIN
#include <cstddef>
#include <benchpress/benchpress.hpp>
//#include "series-benchmark.h"
#include <string>
#include <iostream>
#include <tuple>
#include <type_traits>
#include <piranha/monomial.hpp>
#include <piranha/polynomial.hpp>
#include <piranha/mp_rational.hpp>
#include <piranha/mp_integer.hpp>
#include <gmpxx.h>
using namespace piranha;
using pt = polynomial<rational,piranha::monomial<short>>;
benchpress::auto_register CONCAT2(register_, __LINE__)(("piranha"),
([](benchpress::context* ctx) {
//pt::set_auto_truncate_degree(1000);
pt psin{0}, pcos{1}, x{"x"}, p;
integer prod{1};
for (unsigned int i=0; i<500; i++) {
const short j = 2*i + 1;
if (i != 0)
prod *= 1-j;
prod *= j;
psin += rational{1,prod} * x.pow(j);
}
prod = 1;
for (unsigned int i=1; i<=500; i++) {
const short j = 2*i;
prod *= 1-j;
prod *= j;
pcos += rational{1,prod} * x.pow(j);
}
p = psin * pcos;
ctx->reset_timer();
ctx->start_timer();
for (size_t i = 0; i < ctx->num_iterations(); ++i) {
const short degree = p.degree({"x"});
}
ctx->stop_timer();
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment