[ create a new paste ] login | about

Link: http://codepad.org/FTA8SWtA    [ raw code | output | fork ]

C++, pasted on Feb 18:
#include <iostream>
#include <boost/timer.hpp>
using namespace std;
#define N 1000
#define M N*N
int main(){
	int *p=new int[M];
	int **q=new int*[N];
	for(int i=0;i<N;++i){
		int *t=new int[N];
		q[i]=t;
	}
	boost::timer pt;
	for(int i=0;i<N;++i)
		for(int j=0;j<N;++j)
			p[i*N+j]=(i*j)/1.1;
	cout << pt.elapsed() << endl;

	//勘違い
	boost::timer pt2;
	for(int i=0;i<M;++i)
			p[i/N+i%N]=i/1.1;
	cout << pt2.elapsed() << endl;

	boost::timer pq;
	for(int i=0;i<N;++i)
		for(int j=0;j<N;++j)
			q[i][j]=(i*j)/1.1;
	cout << pq.elapsed() << endl;

	//遅くなるかと思いきや
	boost::timer pq2;
	for(int i=0;i<N;++i)
		for(int j=0;j<N;++j)
			q[j][i]=(i*j)/1.1;
	cout << pq2.elapsed() << endl;
	return 0;
}


Output:
1
2
3
4
5
6
cc1plus: warnings being treated as errors
In function 'int main()':
Line 16: warning: converting to 'int' from 'double'
Line 22: warning: converting to 'int' from 'double'
Line 28: warning: converting to 'int' from 'double'
Line 35: warning: converting to 'int' from 'double'


Create a new paste based on this one


Comments: