Mercurial > op > Looping
view Looping.c @ 12:dab1e83799e4 >>178 tip
R版のソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Sat, 04 Feb 2012 04:10:01 +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; }