aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/benchmark/cast/main.cpp
blob: f604712ab6ba99c134bed642f9850d471add640d (plain) (blame)
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 <library/cpp/testing/benchmark/bench.h>

#include <util/string/cast.h>
#include <util/generic/xrange.h>

char str1[] = "1";
char str12[] = "12";
char str1234[] = "1234";
char str12345678[] = "12345678";

Y_CPU_BENCHMARK(Parse_1, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str1, 1));
    }
}

Y_CPU_BENCHMARK(Parse_12, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str12, 2));
    }
}

Y_CPU_BENCHMARK(Parse_1234, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str1234, 4));
    }
}

Y_CPU_BENCHMARK(Parse_12345678, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str12345678, 8));
    }
}

//atoi
Y_CPU_BENCHMARK(Atoi_1, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(atoi(str1));
    }
}

Y_CPU_BENCHMARK(Atoi_12, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(atoi(str12));
    }
}

Y_CPU_BENCHMARK(Atoi_1234, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(atoi(str1234));
    }
}

Y_CPU_BENCHMARK(Atoi_12345678, iface) {
    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Y_DO_NOT_OPTIMIZE_AWAY(atoi(str12345678));
    }
}