File: quartic_roots_performance.cpp

package info (click to toggle)
boost1.83 1.83.0-4.2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 545,456 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (41 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download | duplicates (11)
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
//  (C) Copyright Nick Thompson 2021.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <random>
#include <array>
#include <vector>
#include <iostream>
#include <benchmark/benchmark.h>
#include <boost/math/tools/quartic_roots.hpp>

using boost::math::tools::quartic_roots;

template<class Real>
void QuarticRoots(benchmark::State& state)
{
    std::random_device rd;
    auto seed = rd();
    // This seed generates 3 real roots:
    //uint32_t seed = 416683252;
    std::mt19937_64 mt(seed);
    std::uniform_real_distribution<Real> unif(-10, 10);

    Real a = unif(mt);
    Real b = unif(mt);
    Real c = unif(mt);
    Real d = unif(mt);
    Real e = unif(mt);
    for (auto _ : state)
    {
        auto roots = quartic_roots(a,b,c,d, e);
        benchmark::DoNotOptimize(roots[0]);
    }
}

BENCHMARK_TEMPLATE(QuarticRoots, float);
BENCHMARK_TEMPLATE(QuarticRoots, double);
BENCHMARK_TEMPLATE(QuarticRoots, long double);

BENCHMARK_MAIN();