view Looping.cpp @ 8:30da8c1da4d4 >>178

SmalltalkやScalar版のベンチマークを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Fri, 18 Feb 2011 19:58:26 +0900
parents 2216535ade9c
children
line wrap: on
line source

#include <stdio.h>
#include <limits.h>
#include <sys/time.h>

class Looping {
public:
	Looping();
	int calc(int n);
private :
	int n0;
};

Looping::Looping(){
	n0 = 0;
}

int Looping::calc(int n){
	int n1 = n0 + (1 - 2*(n%2));
	n0 = n;
	return n1;
}

double gettimeofday_sec()
{
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return tv.tv_sec + (double)tv.tv_usec*1e-6;
}

int main(){
  Looping *o = new Looping();
  unsigned c;
  int n = 1;
  double t1, t2;
  t1 = gettimeofday_sec();
  for(c=0;c<INT_MAX;c++){
    n = o->calc(n);
  }
  t2 = gettimeofday_sec();
  printf("%d\nC++\t%f\n", n, t2 - t1);
  delete o;
  return 0;
}