什么会影响平面阵列的导线性能?

时间:2016-10-16 03:14:50

标签: c++ memory c++14 benchmarking

我现在已经对我的堆栈分配器进行了几个小时的性能测量。每次运行的运行时间通常几乎相同,除了一些非常大的长矛。在当前的运行中,我的性能下降了8倍。

堆栈分配器基本上是坐在堆栈上的原始unsigned char数组。重新分配首先尝试扩展给定的内存,并且它始终在此设置中成功。我已经使用此功能对其进行基准测试:

void stackalloc_benchmark(const current_type* data, std::size_t size)
{
    stack_allocator<131072, alignof(current_type)> allocator; //exactly to fit size elements
    block memory = allocator.allocate(sizeof(current_type) * 8);

    for (std::size_t i = 0; i < size; ++i)
    {
        if (memory.size < sizeof(int) * i)
        {
            allocator.reallocate(memory, memory.size * 2);
        }

        *(to_type(memory.ptr) + i) = *(data + i); //to avoid wordy cast
    }

    allocator.deallocate(memory);
}

data保证正确对齐,因为它来自std::vector<current_type>。分配器中也没有错位,昨天修复了错误。

我使用此代码来计时:

template <typename ... ArgTypes>
void measure(ArgTypes&& ... args)
{
    auto start = std::chrono::high_resolution_clock::now();
    functor(std::forward<ArgTypes>(args)...);
    auto end = std::chrono::high_resolution_clock::now();
    timings.push_back(end - start);
}

设定: current_type = long longsize = 8096runcount = 512,VC ++ 19.0024215.1,CPU:intel i7 2600,不确定RAM频率。发布版本,x64,/ 02,(最大化速度),窗口10。

这些数字大多在9-10微秒左右,有时达到14.在一个地方,它达到了72微秒。

我的问题是:什么会导致性能下降?

0 个答案:

没有答案