# HG changeset patch # User "uncorrelated zombie" # Date 1297745239 -32400 # Node ID 2216535ade9c2ff4a169aa4af8821166976d9098 メンバー関数/メソッド呼び出しのベンチマーク。 diff -r 000000000000 -r 2216535ade9c .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Feb 15 13:47:19 2011 +0900 @@ -0,0 +1,2 @@ +\.class$ +\.exe$ diff -r 000000000000 -r 2216535ade9c Looping.M --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.M Tue Feb 15 13:47:19 2011 +0900 @@ -0,0 +1,45 @@ +#import +#import +#import +#import + +@interface Looping : Object { + int n0; +} +- (id)init; +- (int)calc:(int)n; +@end + +@implementation Looping +- (id)init{ + [super init]; + n0 = 0; + return self; +} +- (int)calc:(int)n { + int n1 = n0 + (1 - 2*(n%2)); + n0 = n; + return n1; +} +@end + +double gettimeofday_sec() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + (double)tv.tv_usec*1e-6; +} + +int main(){ + id o = [[Looping alloc] init]; + unsigned c; + int n = 1; + double t1, t2; + t1 = gettimeofday_sec(); + for(c=0;c +#include +#include +#include + +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 +#include +#include + +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;ccalc(n); + } + t2 = gettimeofday_sec(); + printf("%d\nC++\t%f\n", n, t2 - t1); + delete o; + return 0; +} diff -r 000000000000 -r 2216535ade9c Looping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.java Tue Feb 15 13:47:19 2011 +0900 @@ -0,0 +1,23 @@ + +public class Looping { + private int n0; + public Looping(){ + n0 = 0; + } + public int calc(int n){ + int n1 = n0 + (1 - 2*(n%2)); + n0 = n; + return n1; + } + public static void main(String[] args) { + Looping l = new Looping(); + int n = 1; + long t1, t2; + t1 = System.currentTimeMillis(); + for(int c=0;c