Ai
1 Star 0 Fork 0

green-gitee/博客园

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.cpp 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
green-gitee 提交于 2024-04-16 11:15 +08:00 . Updated resources of 18131080.
// test.cpp
#include <cassert>
#include <cstdlib>
#include <string>
#include "bubble.hxx"
#include "std_out.hxx"
#include "std_random.hxx"
#include "stopwatch.hxx"
#include "type_wrappers.hxx"
namespace blogs
{
static
double
time_trial(int N)
{
Array<Double> a(N);
for (int i = 0; i < N; ++i) a[i] = Std_Random::random();
Stopwatch timer;
Bubble::sort(a);
double time = timer.elapsed_time();
assert(Bubble::is_sorted(a));
return time;
}
static
void
test(char * argv[])
{
int T = std::stoi(argv[1]);
double prev = time_trial(512);
Std_Out::printf("%10s%10s%7s\n", "N", "Time", "Ratio");
for (int i = 0, N = 1024; i < T; ++i, N += N) {
double time = time_trial(N);
Std_Out::printf("%10d%10.3f%7.1f\n", N, time, time/prev);
prev = time;
}
}
} // end of namespace blogs
int
main(int argc, char * argv[])
{
blogs::Std_Out::println();
if (argc != 2) {
blogs::Std_Out::println(
"Usage: /path/to/a.out <T>"
"\n");
std::exit(EXIT_FAILURE);
}
blogs::test(argv);
blogs::Std_Out::println();
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/green-gitee/cnblogs.git
git@gitee.com:green-gitee/cnblogs.git
green-gitee
cnblogs
博客园
master

搜索帮助