aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/benchmark/sort/main.cpp
blob: d58f491f4d5be1db00f499e2305a5121c1ea20f7 (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
67
68
69
70
71
72
73
74
75
76
77
#include <library/cpp/testing/benchmark/bench.h>

#include <util/generic/algorithm.h>
#include <util/generic/vector.h>
#include <util/generic/xrange.h>

Y_CPU_BENCHMARK(Sort1, iface) {
    TVector<int> x = {1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Sort(x);
    }
}

Y_CPU_BENCHMARK(Sort2, iface) {
    TVector<int> x = {2, 1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Sort(x);
    }
}

Y_CPU_BENCHMARK(Sort4, iface) {
    TVector<int> x = {4, 3, 2, 1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Sort(x);
    }
}

Y_CPU_BENCHMARK(Sort16, iface) {
    TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        Sort(x);
    }
}

Y_CPU_BENCHMARK(StableSort1, iface) {
    TVector<int> x = {1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        StableSort(x);
    }
}

Y_CPU_BENCHMARK(StableSort2, iface) {
    TVector<int> x = {2, 1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        StableSort(x);
    }
}

Y_CPU_BENCHMARK(StableSort4, iface) {
    TVector<int> x = {4, 3, 2, 1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        StableSort(x);
    }
}

Y_CPU_BENCHMARK(StableSort16, iface) {
    TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    for (const auto i : xrange(iface.Iterations())) {
        Y_UNUSED(i);
        StableSort(x);
    }
}