- // Kata000.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <boost lambda="" lambda.hpp="">
- #include <boost progress.hpp="">
- void foreachMethod(const size_t& size)
- {
- boost::progress_timer t;
- using namespace boost::lambda;
- using namespace std;
- vector<int> tmpArray(size);
- tmpArray[50] = 200;
- boost::progress_display show_progress( tmpArray.size());
- for_each(
- tmpArray.begin(),
- tmpArray.end(),
- (_1 + 1) );
- }
- void forMethod(const size_t& size)
- {
- boost::progress_timer t;
- using namespace std;
- vector<int> tmpArray(size);
- tmpArray[50] = 200;
- boost::progress_display show_progress( tmpArray.size());
- for( size_t i = 0; i < tmpArray.size(); i++){
- int itt = tmpArray[i] + 1;
- ++show_progress;
- //cout << tmpArray[i] << endl;
- }
- }
- void foriterMethod(const size_t& size)
- {
- boost::progress_timer t;
- using namespace std;
- vector<int> tmpArray(size);
- tmpArray[50] = 200;
- boost::progress_display show_progress( tmpArray.size());
- for(
- vector<int>::const_iterator i = tmpArray.begin();
- i != tmpArray.end(); i++){
- int itt = *i + 1;
- ++show_progress;
- //cout << *i << endl;
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- const size_t size(1000000);
- foreachMethod(size);
- forMethod(size);
- foriterMethod(size);
- return 0;
- }
- </int></int></int></int></boost></boost></algorithm></vector></iostream>
とりあえずいえるのは、VS2008のReleaseならforeachがはやい。Debugならforが早い。とりあえずどれでもイテレータは遅い。でもこの場合に重要な点は、こんな単純なケースで通常のイテレータ回しはあまり有用ではない、という点と、イテレータでの制御はもっと凝ったもののほうがいいかもしれない。とりあえずforeachすげー。投げる要素数が増えるとかなり露骨に早くなる。
0 件のコメント:
コメントを投稿