Mercurial > op > Looping
view Looping.c @ 11:b952a5d72c9f >>178
Luaのソースコードを追加。2ch.netからの転載。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Thu, 24 Feb 2011 22:23:25 +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; }