用于分析多个数据结构的 massif-visualizer
massif-visualizer for profiling multiple data structures
我想,对于任何进行性能研究的人来说,这是一个非常常见的场景。
假设有一些数据结构,并想评估它们的 space 性能——
不计使用例如sizeof
而是以经验的方式。
我在 MWE 中对这种情况建模如下:
- 有一个 STL
stack<in>
并且有一个 set<int>
- 首先我创建
堆栈并将一些(随机)数字压入其中
- 我删除堆栈,
并将一些数字推入集合
- 我运行
valgrind --tool-massif
--max-steps=1000 --time-unit=ms main
- 最后,我使用同名的“massif-visualizer”进行可视化
代码:
#include <set>
#include <stack>
#include <random>
#include <memory>
#include <functional>
using namespace std;
const int n= 42;
std::default_random_engine engine;
std::uniform_int_distribution<int> distribution(0,n-1);
int main() {
unique_ptr<stack<int>> stck;
unique_ptr<set<int>> st;
auto dice= bind(distribution,engine);
{
// first try the stack
stck = make_unique<stack<int>>();
for (auto i = 0; i < 0x420; ++i)
stck->push(dice());
stck.reset();
}
{
// then try the set
st= make_unique<set<int>>();
for (auto i = 0; i < 0x420; ++i)
st->insert(dice());
st.reset();
}
return 0;
}
图片:
当堆栈-> 集合转换发生时,我可以看到明显的分界线。
然而,内存并没有完全释放,看起来——一个人凭直觉(也许天真地)会期待一些 "seesaw" 图像。我们如何实现这种效果?我假设 .reset()
会调用堆栈的析构函数。我想是的,因为在图像的右半部分,工具提示会说话
仅 Rb_tree
(即 set<>
)。我的问题是,massif
工具中的哪个开关或我的代码中的哪种排列会产生更多 "intuitive-looking" 图像?
当然,我可以为我测试的每个数据结构编写相同的样板代码,但我想将它们并列,以便它们的内存性能很容易比较。
那个图中是一个跷跷板。
绿色逐渐消失,让位于蓝色。
只是很难发现,因为大量的堆使用(橙色)被开销(标准库等)占用,这使容器占用的内存相形见绌。
我想,对于任何进行性能研究的人来说,这是一个非常常见的场景。
假设有一些数据结构,并想评估它们的 space 性能——
不计使用例如sizeof
而是以经验的方式。
我在 MWE 中对这种情况建模如下:
- 有一个 STL
stack<in>
并且有一个set<int>
- 首先我创建 堆栈并将一些(随机)数字压入其中
- 我删除堆栈, 并将一些数字推入集合
- 我运行
valgrind --tool-massif --max-steps=1000 --time-unit=ms main
- 最后,我使用同名的“massif-visualizer”进行可视化
代码:
#include <set>
#include <stack>
#include <random>
#include <memory>
#include <functional>
using namespace std;
const int n= 42;
std::default_random_engine engine;
std::uniform_int_distribution<int> distribution(0,n-1);
int main() {
unique_ptr<stack<int>> stck;
unique_ptr<set<int>> st;
auto dice= bind(distribution,engine);
{
// first try the stack
stck = make_unique<stack<int>>();
for (auto i = 0; i < 0x420; ++i)
stck->push(dice());
stck.reset();
}
{
// then try the set
st= make_unique<set<int>>();
for (auto i = 0; i < 0x420; ++i)
st->insert(dice());
st.reset();
}
return 0;
}
图片:
当堆栈-> 集合转换发生时,我可以看到明显的分界线。
然而,内存并没有完全释放,看起来——一个人凭直觉(也许天真地)会期待一些 "seesaw" 图像。我们如何实现这种效果?我假设 .reset()
会调用堆栈的析构函数。我想是的,因为在图像的右半部分,工具提示会说话
仅 Rb_tree
(即 set<>
)。我的问题是,massif
工具中的哪个开关或我的代码中的哪种排列会产生更多 "intuitive-looking" 图像?
当然,我可以为我测试的每个数据结构编写相同的样板代码,但我想将它们并列,以便它们的内存性能很容易比较。
那个图中是一个跷跷板。
绿色逐渐消失,让位于蓝色。
只是很难发现,因为大量的堆使用(橙色)被开销(标准库等)占用,这使容器占用的内存相形见绌。