<commit_before>/*
 * VectorT.cpp
 *
 *  Created on: Nov 19, 2015
 *      Author: ebke
 */

#ifndef BMPREFIX
#error "Do not compile directly."
#endif

#define ASSEMBLE_(PREFIX, SUFFIX) PREFIX ## SUFFIX
#define ASSEMBLE(PREFIX, SUFFIX) ASSEMBLE_(PREFIX, SUFFIX)
#define MYBENCHMARK(NAME) BENCHMARK(NAME)
#define MYBENCHMARK_TEMPLATE(NAME, TYPE) BENCHMARK_TEMPLATE(NAME, TYPE)

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_add_compare)(benchmark::State& state) {
    Vec v1(0, 0, 0);
    Vec v2(1000, 1000, 1000);
    while (state.KeepRunning()) {
        v1 += Vec(1.1, 1.2, 1.3);
        v2 -= Vec(1.1, 1.2, 1.3);
        if (v1 == v2) {
            v1 -= v2;
            v2 += v1;
        }
    }
    // Just so nothing gets optimized away.
    static double dummy;
    dummy = v1.norm() + v2.norm();
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec3f);

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_cross_product)(benchmark::State& state) {
    Vec v1(0, 0, 0);
    Vec v2(1000, 1000, 1000);
    while (state.KeepRunning()) {
        v1 += Vec(1.1, 1.2, 1.3);
        v2 -= Vec(1.1, 1.2, 1.3);
        v1 = (v1 % v2);
    }
    // Just so nothing gets optimized away.
    static double dummy;
    dummy = v1.norm() + v2.norm();
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_cross_product), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_cross_product), OpenMesh::Vec3f);

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_scalar_product)(benchmark::State& state) {
    Vec v1(0, 0, 0);
    Vec v2(1000, 1000, 1000);
    double acc = 0;
    while (state.KeepRunning()) {
        v1 += Vec(1.1, 1.2, 1.3);
        v2 -= Vec(1.1, 1.2, 1.3);
        acc += (v1 | v2);
    }
    // Otherwise GCC will optimize everything away.
    static double dummy;
    dummy = acc;
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec3f);

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_norm)(benchmark::State& state) {
    Vec v1(0, 0, 0);
    double acc = 0;
    while (state.KeepRunning()) {
        v1 += Vec(1.1, 1.2, 1.3);
        acc += v1.norm();
    }
    // Otherwise GCC will optimize everything away.
    static double dummy;
    dummy = acc;
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec3f);<commit_msg>Further templatized benchmarks. Testing Vec4* now as well.<commit_after>/*
 * VectorT.cpp
 *
 *  Created on: Nov 19, 2015
 *      Author: ebke
 */

#ifndef BMPREFIX
#error "Do not compile directly."
#endif

#define ASSEMBLE_(PREFIX, SUFFIX) PREFIX ## SUFFIX
#define ASSEMBLE(PREFIX, SUFFIX) ASSEMBLE_(PREFIX, SUFFIX)
#define MYBENCHMARK(NAME) BENCHMARK(NAME)
#define MYBENCHMARK_TEMPLATE(NAME, TYPE) BENCHMARK_TEMPLATE(NAME, TYPE)

template<class Vec>
static inline
typename std::enable_if<Vec::size_ == 3, Vec>::type
testVec() {
    return Vec(1.1, 1.2, 1.3);
}

template<class Vec>
static inline
typename std::enable_if<Vec::size_ == 4, Vec>::type
testVec() {
    return Vec(1.1, 1.2, 1.3, 1.4);
}

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_add_compare)(benchmark::State& state) {
    Vec v1(0.0);
    Vec v2(1000.0);
    while (state.KeepRunning()) {
        v1 += testVec<Vec>();
        v2 -= testVec<Vec>();
        if (v1 == v2) {
            v1 -= v2;
            v2 += v1;
        }
    }
    // Just so nothing gets optimized away.
    static double dummy;
    dummy = v1.norm() + v2.norm();
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec4f);

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_cross_product)(benchmark::State& state) {
    Vec v1(0.0);
    Vec v2(1000.0);
    while (state.KeepRunning()) {
        v1 += testVec<Vec>();
        v2 -= testVec<Vec>();
        v1 = (v1 % v2);
    }
    // Just so nothing gets optimized away.
    static double dummy;
    dummy = v1.norm() + v2.norm();
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_cross_product), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_cross_product), OpenMesh::Vec3f);

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_scalar_product)(benchmark::State& state) {
    Vec v1(0.0);
    Vec v2(1000.0);
    double acc = 0;
    while (state.KeepRunning()) {
        v1 += testVec<Vec>();
        v2 -= testVec<Vec>();
        acc += (v1 | v2);
    }
    // Otherwise GCC will optimize everything away.
    static double dummy;
    dummy = acc;
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec4f);

template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_norm)(benchmark::State& state) {
    Vec v1(0.0);
    double acc = 0;
    while (state.KeepRunning()) {
        v1 += testVec<Vec>();
        acc += v1.norm();
    }
    // Otherwise GCC will optimize everything away.
    static double dummy;
    dummy = acc;
}

MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec4f);
{'fraction_non_alphanumeric': 0.14155172413793105, 'fraction_numerical': 0.039310344827586205, 'mean_word_length': 3.8021523178807946, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6057512', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2272, 'n_words': 481}