【发布时间】:2012-04-23 06:47:41
【问题描述】:
I am referring you to a previous link that compares the performance of qsort vs stdsort.
我编写了一个填充大std::map 的 C 程序,我想对数组进行排序。我目前使用的是qsort。
typedef std::map<uint16_t, uint32_t> TSrcMap;
TPSrcMap sp;
TSrcMap::iterator its;
/*Code to populate the array_start.*/
/*Code to populate the array_end.*/
typedef struct port_count
{
uint32_t port_number;
uint32_t port_count;
}port_count_t;
port_count_t pcount[10];
memset(pcount,0,sizeof(pcount));
size_t structs_len = sizeof(pcount)/sizeof(port_count_t);
for(its = stcp.begin(); its != stcp.end();its++)
{
if(pcount[smallest_index].port_count < (*its).second)
{
pcount[smallest_index].port_count = (*its).second;
pcount[smallest_index].port_number = (*its).first;
/*qsort(pcount, structs_len, sizeof(port_count_t), struct_cmp_by_port_count);*/
std::sort(pcount,sizeof(port_count_t));
}
}
qsort 函数正在正确地对数组进行排序。我想比较qsort 和std::sort 的性能,但是调用std::sort 会出现编译错误
没有匹配函数调用
‘sort(port_count_t [10], long unsigned int)’
我想比较std::sort 和qsort 算法的性能。我该怎么做?
【问题讨论】:
-
如果您认为您的问题已得到解答,请接受相应的答案。
标签: c++ dictionary std stdmap qsort