|
楼主 |
发表于 2022-1-22 11:55:00
|
显示全部楼层
验证代码如下
#include <iostream>
#include <vector>
#include <algorithm>
#include "MyTimer.h"
#include <stdlib.h>
using namespace std;
const int C_Size = 100000;
int Compare(const void *a,const void *b)
{
return (*(int *)a - *(int *)b);
}
int main()
{
vector<int> num;
int i,element;
int array[C_Size];
MyTimer mt;
cout << "排序规模为:" << C_Size << endl;
for(i=0;i<C_Size;i++)
{
element = rand()%1000;
num.push_back(element);
array[i] = rand()%1000;
}
mt.Start();
sort(num.begin(),num.end());
mt.End();
cout << "sort() cost time:" << mt.costTime << " us" << endl;
mt.Reset();
mt.Start();
qsort(array,C_Size,sizeof(int),Compare);
mt.End();
cout << "qsort() cost time:" << mt.costTime << " us" << endl;
return 0;
} |
|