对拍,考场干货
Arunner.cpp
#include<bits/stdc++.h>
using namespace std;
long long tmp,cnt=0,t1=0,t2=0,lim;
inline void start(){tmp=clock();}
inline long long end(){return clock()-tmp;}
signed main(){
cout<<"Input times(-1 for infinity):"<<endl;
cin>>lim;
while(cnt!=lim){
system("Amake.exe > Adata.txt");
start();
system("1.exe < Adata.txt > A1.txt");
t1+=end();
start();
system("2.exe < Adata.txt > A2.txt");
t2+=end();
cnt++;
if(system("fc A1.txt A2.txt")){
cout<<"There's something wrong."<<endl;
system("pause");
return 0;
}
}
cout<<cnt<<" times running."<<endl;
cout<<"Avg time of 1: "<<fixed<<setprecision(3)<<0.001*t1/cnt<<endl;
cout<<"Avg time of 2: "<<fixed<<setprecision(3)<<0.001*t2/cnt<<endl;
system("pause");
return 0;
}
Amake.cpp
写随机数据的地方,不用 freopen。
缺省源:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fir first
#define sec second
#define mkp make_pair
#define pb emplace_back
#define mem(x,y) memset(x,y,sizeof(x))
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Rof(i,j,k) for(int i=j;i>=k;i--)
#define ckmx(a,b) a=max(a,b)
#define ckmn(a,b) a=min(a,b)
#define uid(i,j,k) uniform_int_distribution<ll> i(j,k)
#define Rand(s) s(rand_num)
unsigned seed=chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(seed);
signed main(){IOS;
return 0;}
1.cpp & 2.cpp
两个比较程序,不用写 freopen。
注意每次对拍前要编译,否则 .exe
文件没被修改。
原文链接: https://www.cnblogs.com/shaojia/p/15430360.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/185455
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!