bench-fibo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://logand.com/git/bench-fibo.git/
Log | Files | Refs | README

commit 143389d85fd93368542a88d0d6dec1e39a25ebad
parent 5a87106d083b1e060665a172b133789acdf4adc2
Author: Tomas Hlavaty <tom@logand.com>
Date:   Fri, 22 Oct 2010 01:29:11 +0200

added ofibo40.m fibo40int.java fibo40.java

Diffstat:
MMakefile | 16++++++++++++++--
Afibo40.java | 17+++++++++++++++++
Afibo40int.java | 11+++++++++++
Aofibo40.m | 21+++++++++++++++++++++
4 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,10 +1,19 @@ -all: fibo40 +all: fibo40 ofibo40 fibo40int.class fibo40.class .c.l: fibo40: fibo40.c gcc -O2 -o fibo40 fibo40.c +ofibo40: ofibo40.m + gcc -g -O2 -Wall -o ofibo40 ofibo40.m -lobjc + +fibo40int.class: fibo40int.java + javac fibo40int.java + +fibo40.class: fibo40.java + javac fibo40.java + bench: cat fibo25.l | time ~/lisp/picoLisp-3.0.4/bin/picolisp cat fibo30.l | time ~/lisp/picoLisp-3.0.4/bin/picolisp @@ -16,6 +25,9 @@ bench: cat fibo30.lua | time luajit-2.0.0-beta2 cat fibo40.lua | time luajit-2.0.0-beta2 time ./fibo40 + time ./ofibo40 + time java fibo40int + time java fibo40 clean: - rm -f *~ *.o fibo40 + rm -f *~ *.o fibo40 ofibo40 fibo40int.class fibo40.class diff --git a/fibo40.java b/fibo40.java @@ -0,0 +1,17 @@ +import java.math.BigInteger; + +class fibo40 { + + final static BigInteger one = BigInteger.ONE; + final static BigInteger two = BigInteger.ONE.add(one); + final static BigInteger three = BigInteger.ONE.add(two); + + final static BigInteger fibo(BigInteger n) { + if(-1 == n.compareTo(three)) return n; + else return fibo(n.subtract(one)).add(fibo(n.subtract(two))); + } + + public static void main(String args[]) { + System.out.println(fibo(new BigInteger("40"))); + } +} diff --git a/fibo40int.java b/fibo40int.java @@ -0,0 +1,11 @@ +class fibo40int { + + final static int fibo(int n) { + if(n < 3) return n; + else return fibo(n - 1) + fibo(n - 2); + } + + public static void main(String args[]) { + System.out.println(fibo(40)); + } +} diff --git a/ofibo40.m b/ofibo40.m @@ -0,0 +1,21 @@ +#import <objc/Object.h> + +@interface Fibo : Object +- (int) fibo: (int) n; +@end + +//------------- + +#include <stdio.h> + +@implementation Fibo +- (int) fibo: (int) n { + if(n < 3) return n; + else return [self fibo: n - 1] + [self fibo: n - 2]; +} +@end + +int main() { + printf("%d\n", [[[Fibo alloc] init] fibo: 40]); + return 0; +}