Blame test/performance/perf_tests.hpp

Packit 345191
/*
Packit 345191
* Copyright (C) 2014 - 2018 Intel Corporation.
Packit 345191
* All rights reserved.
Packit 345191
*
Packit 345191
* Redistribution and use in source and binary forms, with or without
Packit 345191
* modification, are permitted provided that the following conditions are met:
Packit 345191
* 1. Redistributions of source code must retain the above copyright notice(s),
Packit 345191
*    this list of conditions and the following disclaimer.
Packit 345191
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
Packit 345191
*    this list of conditions and the following disclaimer in the documentation
Packit 345191
*    and/or other materials provided with the distribution.
Packit 345191
*
Packit 345191
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
Packit 345191
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Packit 345191
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
Packit 345191
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 345191
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 345191
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit 345191
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit 345191
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
Packit 345191
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit 345191
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 345191
*/
Packit 345191
Packit 345191
#pragma once
Packit 345191
Packit 345191
#include "framework.hpp"
Packit 345191
#include "operations.hpp"
Packit 345191
Packit 345191
using std::vector;
Packit 345191
using std::string;
Packit 345191
Packit 345191
using performance_tests::Operation;
Packit 345191
using performance_tests::OperationName;
Packit 345191
using performance_tests::Metrics;
Packit 345191
using performance_tests::ExecutionMode;
Packit 345191
Packit 345191
template <class T>
Packit 345191
class PerfTestCase
Packit 345191
{
Packit 345191
Packit 345191
private:
Packit 345191
    vector<vector<Operation *>> m_testOperations;
Packit 345191
    Operation *m_freeOperation;
Packit 345191
    performance_tests::PerformanceTest *m_test;
Packit 345191
    const unsigned m_seed = 1297654;
Packit 345191
    const unsigned m_repeats = 50;
Packit 345191
    const unsigned m_threads = 64;
Packit 345191
    const unsigned m_iterations = 100;
Packit 345191
Packit 345191
public:
Packit 345191
    PerfTestCase()
Packit 345191
    {
Packit 345191
        m_freeOperation = new T(OperationName::Free);
Packit 345191
        srand(m_seed);
Packit 345191
        m_test = nullptr;
Packit 345191
    }
Packit 345191
Packit 345191
    ~PerfTestCase()
Packit 345191
    {
Packit 345191
        delete m_test;
Packit 345191
        for (vector<Operation *> ops : m_testOperations) {
Packit 345191
            for (Operation *op : ops) {
Packit 345191
                delete op;
Packit 345191
            }
Packit 345191
        }
Packit 345191
    }
Packit 345191
Packit 345191
    // Perform common actions for all test cases
Packit 345191
    Metrics runTest(vector<memkind_t> kinds = { MEMKIND_DEFAULT })
Packit 345191
    {
Packit 345191
        m_test->setKind(kinds);
Packit 345191
        m_test->showInfo();
Packit 345191
        m_test->run();
Packit 345191
        return m_test->getMetrics();
Packit 345191
    }
Packit 345191
Packit 345191
    // malloc only
Packit 345191
    // 128 bytes
Packit 345191
Packit 345191
    void setupTest_singleOpSingleIter()
Packit 345191
    {
Packit 345191
Packit 345191
        m_testOperations = { { new T(OperationName::Malloc) } };
Packit 345191
Packit 345191
        m_test = new performance_tests::PerformanceTest(m_repeats, m_threads,
Packit 345191
                                                        m_iterations * 10);
Packit 345191
        m_test->setOperations(m_testOperations, m_freeOperation);
Packit 345191
        m_test->setAllocationSizes({ 128 });
Packit 345191
    }
Packit 345191
Packit 345191
    // malloc, calloc, realloc and align (equal probability)
Packit 345191
    // 120, 521, 1200 and 4099 bytes
Packit 345191
    void setupTest_manyOpsSingleIter()
Packit 345191
    {
Packit 345191
        m_testOperations = { {
Packit 345191
                new T(OperationName::Malloc, 25),
Packit 345191
                new T(OperationName::Calloc, 50),
Packit 345191
                new T(OperationName::Realloc, 75),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            }
Packit 345191
        };
Packit 345191
Packit 345191
        m_test = new performance_tests::PerformanceTest(m_repeats, m_threads,
Packit 345191
                                                        m_iterations * 10);
Packit 345191
        m_test->setOperations(m_testOperations, m_freeOperation);
Packit 345191
        m_test->setAllocationSizes({ 120, 521, 1200, 4099 });
Packit 345191
    }
Packit 345191
Packit 345191
    // malloc, calloc, realloc and align (equal probability)
Packit 345191
    // 500000, 1000000, 2000000 and 4000000 bytes
Packit 345191
    void setupTest_manyOpsSingleIterHugeAlloc()
Packit 345191
    {
Packit 345191
        m_testOperations = { {
Packit 345191
                new T(OperationName::Malloc, 25),
Packit 345191
                new T(OperationName::Calloc, 50),
Packit 345191
                new T(OperationName::Realloc, 75),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            }
Packit 345191
        };
Packit 345191
Packit 345191
        m_test = new performance_tests::PerformanceTest(m_repeats, m_threads,
Packit 345191
                                                        m_iterations);
Packit 345191
        m_test->setOperations(m_testOperations, m_freeOperation);
Packit 345191
        m_test->setAllocationSizes({ 500000, 1000000, 2000000, 4000000 });
Packit 345191
    }
Packit 345191
Packit 345191
    // 4 iterations of each thread (first malloc, then calloc, realloc and align)
Packit 345191
    // 120, 521, 1200 and 4099 bytes
Packit 345191
    void setupTest_singleOpManyIters()
Packit 345191
    {
Packit 345191
        m_testOperations = {
Packit 345191
            { new T(OperationName::Malloc, 100) },
Packit 345191
            { new T(OperationName::Calloc, 100) },
Packit 345191
            { new T(OperationName::Realloc, 100) },
Packit 345191
            { new T(OperationName::Align, 100) }
Packit 345191
        };
Packit 345191
Packit 345191
        m_test = new performance_tests::PerformanceTest(m_repeats, m_threads,
Packit 345191
                                                        m_iterations * 10);
Packit 345191
        m_test->setOperations(m_testOperations, m_freeOperation);
Packit 345191
        m_test->setAllocationSizes({ 120, 521, 1200, 4099 });
Packit 345191
        m_test->setExecutionMode(ExecutionMode::ManyIterations);
Packit 345191
    }
Packit 345191
Packit 345191
    // 4 iterations of each thread, all with same set of operations (malloc, then calloc, realloc and align),
Packit 345191
    // but different operation probability
Packit 345191
    // 120, 521, 1200 and 4099 bytes
Packit 345191
    void setupTest_manyOpsManyIters()
Packit 345191
    {
Packit 345191
        m_testOperations = {
Packit 345191
            {
Packit 345191
                new T(OperationName::Malloc, 25),
Packit 345191
                new T(OperationName::Calloc, 50),
Packit 345191
                new T(OperationName::Realloc, 75),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            },
Packit 345191
            {
Packit 345191
                new T(OperationName::Malloc, 50),
Packit 345191
                new T(OperationName::Calloc, 70),
Packit 345191
                new T(OperationName::Realloc, 80),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            },
Packit 345191
            {
Packit 345191
                new T(OperationName::Calloc, 50),
Packit 345191
                new T(OperationName::Malloc, 60),
Packit 345191
                new T(OperationName::Realloc, 75),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            },
Packit 345191
            {
Packit 345191
                new T(OperationName::Realloc, 60),
Packit 345191
                new T(OperationName::Malloc, 80),
Packit 345191
                new T(OperationName::Calloc, 90),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            },
Packit 345191
            {
Packit 345191
                new T(OperationName::Realloc, 40),
Packit 345191
                new T(OperationName::Malloc, 55),
Packit 345191
                new T(OperationName::Calloc, 70),
Packit 345191
                new T(OperationName::Align, 100)
Packit 345191
            }
Packit 345191
        };
Packit 345191
Packit 345191
        m_test = new performance_tests::PerformanceTest(m_repeats, m_threads,
Packit 345191
                                                        m_iterations * 10);
Packit 345191
        m_test->setOperations(m_testOperations, m_freeOperation);
Packit 345191
        m_test->setAllocationSizes({ 120, 521, 1200, 4099 });
Packit 345191
        m_test->setExecutionMode(ExecutionMode::ManyIterations);
Packit 345191
    }
Packit 345191
};