Mercurial > op > Looping
view Looping.c @ 0:2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Tue, 15 Feb 2011 13:47:19 +0900 |
parents | |
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; }