Esempio n. 1
0
inline void eraseContainer(std::vector<T>& vec) {
    { asm(""); }
    for (int i = 0; i < getTestSize(); ++i) {
        auto iter = std::find(vec.begin(), vec.end(), i);
        vec.erase(iter);
    }
}
Esempio n. 2
0
 NO_INLINE
 double testDouble(double f) {
     for (int i = 0; i < getTestSize(); ++i) {
         auto t = cos(f);
         if (pow(t, 3.0) < 0.5) {
             t += 5 * t;
             t -= 2 * sin(t);
         }
         f += t;
         if (f > 0.1) {
             f /= 10.0;
             f += randomFloat();
         }
         f *= 196.0;
     }
     return f;
 }
Esempio n. 3
0
    NO_INLINE
    float testFloat(float f) {
        for (int i = 0; i < getTestSize(); ++i) {
            auto t = cosf(f);
            if (powf(t, 3.0f) < 0.5f) {
                t += 5 * t;
                t -= 2 * sinf(t);
            }
            f += t;
            if (f > 0.1f) {
                f /= 10.0f;
                f += randomFloat();
            }
            f *= 196.0f;
        }
        return f;

    }
Esempio n. 4
0
inline void test() {
    std::cout << "Testing cache misses ..." << std::endl;
    static std::vector<int> source;
    source.reserve(getTestSize());
    for (int i = 0; i < getTestSize(); ++i)
        source.push_back(i);
    
    std::random_shuffle(source.begin(), source.end());

    auto test0 = [&]{
        std::vector<int> vecStd;
        vecStd.reserve(source.size());
        for (int i = 0; i < getTestSize(); ++i)
            vecStd.push_back(source[i]);
        eraseContainer(vecStd);
    };
    
    auto test1 = [&]{
        std::list<int> listStd;
        for (int i = 0; i < getTestSize(); ++i)
            listStd.push_back(source[i]);
        eraseContainer(listStd);
    };
    
    auto test2 = [&]{
        Vector<int> vecCustom;
        vecCustom.reset((int)getTestSize());
        for (int i = 0; i < getTestSize(); ++i)
            vecCustom.add(source[i]);
        eraseContainer(vecCustom);
    };
    
    auto test3 = [&]{
        List<int> listCustom;
        for (int i = 0; i < getTestSize(); ++i)
            listCustom.add(source[i]);

        eraseContainer(listCustom);
    };
    
    //-----
    
    auto numRuns = 256;
    auto l1size = 32 * 1024 / sizeof(float) /*ints*/;
    auto size = l1size * 16;
    std::unique_ptr<float[]> array(new float[size]);
    std::fill(array.get(), array.get() + size, 0.f);
    
    auto test4 = [&] {
        for (int i=0; i<numRuns; i++)
            for (int j=0; j<size; j++)
                array[j] = 2.3*array[j]+1.2;
    };
    
    auto test5 = [&] {
        int blockstart = 0;
        const auto numBuckets = size/l1size;
        for (int b=0; b<numBuckets; b++) {
            for (int i=0; i<numRuns; i++) {
                for (int j=0; j<l1size; j++)
                    array[blockstart+j] = 2.3*array[blockstart+j]+1.2;
            }
            blockstart += l1size;
        }
    };
    
    ADD_BENCHMARK("CacheMiss \t std::vector", test0);
    ADD_BENCHMARK("CacheMiss \t std::list", test1);
    ADD_BENCHMARK("CacheMiss \t custom vector", test2);
    ADD_BENCHMARK("CacheMiss \t custom vector", test3);
    //ADD_BENCHMARK("CacheMiss \t linear add", test4);
    //ADD_BENCHMARK("CacheMiss \t bucket add", test5);

    benchpress::run_benchmarks(benchpress::options());
    
}
Esempio n. 5
0
inline void eraseContainer(T& container) {
    { asm(""); }
    for (int i = 0; i < getTestSize(); ++i)
        container.remove(i);
}