summaryrefslogtreecommitdiff
path: root/benchmark/util/dtoa.benchmark.cpp
blob: 0009c6dd15704295a90b9b95dbaec80ede0be971 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <benchmark/benchmark.h>

#include <mbgl/util/dtoa.hpp>

#include <cfloat>
#include <cmath>

using namespace mbgl;

static void Util_dtoa(::benchmark::State& state) {
    while (state.KeepRunning()) {
        util::dtoa(0.);
        util::dtoa(M_E);
        util::dtoa(M_LOG2E);
        util::dtoa(M_LOG10E);
        util::dtoa(M_LN2);
        util::dtoa(M_LN10);
        util::dtoa(M_PI);
        util::dtoa(M_PI_2);
        util::dtoa(M_PI_4);
        util::dtoa(M_1_PI);
        util::dtoa(M_2_PI);
        util::dtoa(M_2_SQRTPI);
        util::dtoa(M_SQRT2);
        util::dtoa(M_SQRT1_2);
    }
}

static void Util_standardDtoa(::benchmark::State& state) {
    while (state.KeepRunning()) {
        std::to_string(0.);
        std::to_string(M_E);
        std::to_string(M_LOG2E);
        std::to_string(M_LOG10E);
        std::to_string(M_LN2);
        std::to_string(M_LN10);
        std::to_string(M_PI);
        std::to_string(M_PI_2);
        std::to_string(M_PI_4);
        std::to_string(M_1_PI);
        std::to_string(M_2_PI);
        std::to_string(M_2_SQRTPI);
        std::to_string(M_SQRT2);
        std::to_string(M_SQRT1_2);
    }
}

static void Util_dtoaLimits(::benchmark::State& state) {
    while (state.KeepRunning()) {
        util::dtoa(DBL_MIN);
        util::dtoa(DBL_MAX);
    }
}

static void Util_standardDtoaLimits(::benchmark::State& state) {
    while (state.KeepRunning()) {
        std::to_string(DBL_MIN);
        std::to_string(DBL_MAX);
    }
}

BENCHMARK(Util_dtoa);
BENCHMARK(Util_standardDtoa);

BENCHMARK(Util_dtoaLimits);
BENCHMARK(Util_standardDtoaLimits);