view Looping.c @ 7:69b8c75e9c24 default

Scalaのソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Fri, 18 Feb 2011 10:32:06 +0900
parents 2216535ade9c
children
line wrap: on
line source

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

typedef struct {
	int n0;
} Looping;

int calc(Looping *s, int n){
	int n1 = s->n0 + (1 - 2*(n%2));
	s->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;
  unsigned c;
  int n = 1;
  double t1, t2;

  o = (Looping *)malloc(sizeof(Looping));
  o->n0 = 0;

  t1 = gettimeofday_sec();
  for(c=0;c<INT_MAX;c++){
    n = calc(o, n);
  }
  t2 = gettimeofday_sec();
  printf("%d\nC\t%f\n", n, t2 - t1);

  free(o);
  return 0;
}