各プログラムではパフォーマンス等を考慮していません。
動けばよし。
outputファイルはすべてシェルスクリプトで生成しているものであって、プログラム内では標準出力しかしていません。
meantime.cpp
各outputから実行時間を取り出し、平均値を計算。その後、すべての結果をまとめて表示する。
入力:outputX (X = 00〜39)
出力:output_Y (Y = n,p)
#include<iostream>
#include<string>
#include<list>
#include<fstream>
#include<stdlib.h>
using namespace std;
double todouble(string str){
return atof(str.c_str());
}
int main(int argc, char *argv[]){
list<string> data; //計算時間を保持するリスト
int n_out = atoi(argv[1]); //コマンドライン引数でファイル数を入力
for(int j = 0; j < n_out; j++){
char num[2];
sprintf(num,"%d",j); //ファイル番号取得
char filename[9];
//ファイル番号に応じて入力形式を変化
if(j < 10){
filename[0] = 'o';
filename[1] = 'u';
filename[2] = 't';
filename[3] = 'p';
filename[4] = 'u';
filename[5] = 't';
filename[6] = '0';
filename[7] = num[0];
filename[8] = '\0';
}
else if(j >= 10){
filename[0] = 'o';
filename[1] = 'u';
filename[2] = 't';
filename[3] = 'p';
filename[4] = 'u';
filename[5] = 't';
filename[6] = num[0];
filename[7] = num[1];
filename[8] = '\0';
}
cout << filename << endl;
ifstream fs;
string tmp;
fs.open(filename); //ファイルオープン
//outputファイルの仕様に応じて、必要な部分を保存する
while(true){
getline(fs, tmp, '\n');
if(tmp != "times")
cout << tmp << endl;
if(tmp == "times"){
getline(fs, tmp, '\n');
cout << tmp << endl;
data.push_back(tmp);
break;
}
if(fs.eof())
break;
}
fs.close();
}
//各値の出力と平均の計算
double time[n_out];
double mean = 0;
cout << endl;
cout << "times" << endl;
list<string>::iterator it_d = data.begin();
for(int k = 0; k < n_out; k++){
cout << k << " : " << *it_d << endl;
time[k] = todouble(*it_d);
mean += time[k];
++it_d;
}
++it_d;
mean /= n_out;
cout << "mean" << endl;
cout << mean << endl;
return 0;
}
mt_cmp.cpp
meantimeで作った新たなoutputを用いて、比較用の時間をまとめたファイルを作る
入力:output_Y (Y = n,p)
出力:output_cmp
#include<iostream>
#include<string>
#include<list>
#include<fstream>
#include<stdlib.h>
using namespace std;
double todouble(string str){
return atof(str.c_str());
}
int main(int argc, char *argv[]){
int n_out = atoi(argv[1]);
list<string> mean;
list<string> data_n;
list<string> data_p;
//未高速化の計算時間ファイル読み込み
char filename[9];
filename[0] = 'o';
filename[1] = 'u';
filename[2] = 't';
filename[3] = 'p';
filename[4] = 'u';
filename[5] = 't';
filename[6] = '_';
filename[7] = 'n';
filename[8] = '\0';
//cout << filename << endl;
ifstream fs; //ファイルストリーム
string tmp; //データ一時保存用変数
fs.open(filename); //ファイルオープン
//データの取り込み
while(true){
getline(fs, tmp, '\n');
//cout << tmp << endl;
if(tmp == "times"){
for(int j = 0; j < n_out; j++){
getline(fs, tmp, '\n');
data_n.push_back(tmp);
}
}
if(tmp == "mean"){
getline(fs, tmp, '\n');
mean.push_back(tmp);
break;
}
if(fs.eof())
break;
}
fs.close();
//高速化の計算時間ファイル読み込み
filename[7] = 'p';
//cout << filename << endl;
fs.open(filename); //ファイルオープン
//データの取り込み
while(true){
getline(fs, tmp, '\n');
//cout << tmp << endl;
if(tmp == "times"){
for(int j = 0; j < n_out; j++){
getline(fs, tmp, '\n');
data_p.push_back(tmp);
}
}
if(tmp == "mean"){
getline(fs, tmp, '\n');
mean.push_back(tmp);
break;
}
if(fs.eof())
break;
}
fs.close();
//すべての時間を並べて出力
list<string>::iterator it_m = mean.begin();
list<string>::iterator it_dn = data_n.begin(); //1行でのデータのリスト
list<string>::iterator it_dp = data_p.begin();
cout << "output_n output_p" << endl;
for(int j = 0; j < n_out;j++){
cout << *it_dn << " " << *it_dp<< endl;
++it_dn;
++it_dp;
}
double n,p;
cout << endl;
cout << "mean_n : " << *it_m << endl;
n = todouble(*it_m);
++it_m;
cout << "mean_p : " << *it_m << endl;
p = todouble(*it_m);
cout << "diff : " << n-p << endl;
return 0;
}
最終更新:2009年06月02日 11:06