File: contour_test_perf.cpp

package info (click to toggle)
msc-generator 8.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 180,484 kB
  • sloc: cpp: 129,931; yacc: 23,655; ansic: 7,464; sh: 5,026; makefile: 948
file content (70 lines) | stat: -rw-r--r-- 2,081 bytes parent folder | download | duplicates (2)
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
#include <iostream>
#include <benchmark/benchmark.h>
#include <contour.h>


using contour::Contour;
using contour::Path;
using contour::XY;

static Contour GenerateBoxy(int num) {
    Contour A(0, 10, 0, 10), res = A;
    for (int i = 0; i < num; i++)
        res += A.Shift(XY(5, 5));
    return res;
}

static Contour GenerateCurvy(int num) {
    Contour A(XY(5,5), 4), res = A;
    for (int i = 0; i < num; i++)
        res += A.Shift(XY(5, 5));
    return res;
}

constexpr int mul_ = 16, max_ = 256;

static void ExpandBoxy(benchmark::State& state) {
    Contour x = GenerateBoxy(state.range(0));
    for (auto _ : state)
        benchmark::DoNotOptimize(x.CreateExpand(1));
}
BENCHMARK(ExpandBoxy)->RangeMultiplier(mul_)->Range(1, max_);

static void ExpandBoxyRotate(benchmark::State& state) {
    Contour x = GenerateBoxy(state.range(0));
    x.Rotate(15);
    for (auto _ : state)
        benchmark::DoNotOptimize(x.CreateExpand(1));
}
BENCHMARK(ExpandBoxyRotate)->RangeMultiplier(mul_)->Range(1, max_);

static void ExpandCurvy(benchmark::State& state) {
    Contour x = GenerateCurvy(state.range(0));
    for (auto _ : state)
        benchmark::DoNotOptimize(x.CreateExpand(1));
}
BENCHMARK(ExpandCurvy)->RangeMultiplier(mul_)->Range(1, max_);

static void UnionBoxy(benchmark::State& state) {
    Contour x = GenerateBoxy(state.range(0)), y = x.CreateShifted(XY(1,1));
    for (auto _ : state)
        benchmark::DoNotOptimize(x+y);
}
BENCHMARK(UnionBoxy)->RangeMultiplier(mul_)->Range(1, max_);

static void UnionBoxyRotate(benchmark::State& state) {
    Contour x = GenerateBoxy(state.range(0)), y = x.CreateShifted(XY(1, 1));
    x.Rotate(15); y.Rotate(15);
    for (auto _ : state)
        benchmark::DoNotOptimize(x+y);
}
BENCHMARK(UnionBoxyRotate)->RangeMultiplier(mul_)->Range(1, max_);

static void UnionCurvy(benchmark::State& state) {
    Contour x = GenerateCurvy(state.range(0)), y = x.CreateShifted(XY(1, 1));
    for (auto _ : state)
        benchmark::DoNotOptimize(x+y);
}
BENCHMARK(UnionCurvy)->RangeMultiplier(mul_)->Range(1, max_);

BENCHMARK_MAIN();