Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

niceperl (8613)

niceperl
  (email not shown publicly)
+ -

  Comment: interface (Score 1) on 2009.10.07 14:39

by niceperl on 2009.10.07 14:39 (#70808)
Attached to: Object Responsibilities versus Object Behavior
the first time I heard about this concept was in 1996, studying the Java interface keyword. And the next step is "programming oriented to the interface", thinking in classes is bad. You must design witn roles in mind.
Read More 7 comments
Comments: 7
+ -

  fibonacci numbers on 2008.09.13 4:53 niceperl

Submitted by niceperl on 2008.09.13 4:53
User Journal
niceperl writes "I wrote a small script in Perl to calc the N first terms of fibonnaci serie:

#-- fibo script

sub fibo {
    return 1 if( $_[0] < 2 ) ;
    return fibo($_[0]-1) + fibo($_[0]-2);
}

for($i=0; $i<=40; $i++) {
    $f = fibo($i);
    print "$i : $f\n";
}

#-- eof fibo.pl

I tried to calc the first 40 numbers, it tooks in my PC about. I weren't worried about writting a fast algoritm, just curious about the performance of a recursive call algorithm.

A friend of me, advertised me that the similar Java version code, ran fast, so I tried:

// Java fibonnaci class

class  fibo {

    public static long calc(long x) {
        if( x < 2 ) return 1;
        return calc(x-1) + calc(x-2);
    }

    public static void main(String s[]) {
        for(int i=0; i<=40; i++) {
            System.out.println(i + " : " + calc(i));
        }
    }
}
// EOF Java fibonnaci class

----------------------------
The results (40 terms calc):
1) Perl: 16 minutes
2) Java: 16 seconds (!)

I'm sure that Java does some kind of optimization at the Virtual Machine.
I hope that Parrot team will be able to make a very fast virtual machine...
"
Read More 0 comments

+ -

  Journal: fibonacci numbers on 2008.09.13 4:53

Journal by niceperl on 2008.09.13 4:53
User Journal
I wrote a small script in Perl to calc the N first terms of Fibonacci serie:

#-- fibo script

sub fibo {
    return 1 if( $_[0] < 2 ) ;
    return fibo($_[0]-1) + fibo($_[0]-2);
}

for($i=0; $i<=40; $i++) {
    $f = fibo($i);
    print "$i : $f\n";
}

#-- eof fibo.pl

I tried to calc the first 40 numbers, it tooks in my PC about 16 minutes. I weren't worried about writting a fast algoritm, just curious about the performance of a recursive call algorithm.

A friend of me, advertised me that the similar Java version code, ran fast, so I tried:

// Java fibonnaci class

class  fibo {

    public static long calc(long x) {
        if( x < 2 ) return 1;
        return calc(x-1) + calc(x-2);
    }

    public static void main(String s[]) {
        for(int i=0; i<=40; i++) {
            System.out.println(i + " : " + calc(i));
        }
    }
}
// EOF Java fibonnaci class

----------------------------
The results (40 terms calc):
1) Perl: 16 minutes
2) Java: 16 seconds (!)

I'm sure that Java does some kind of optimization at the Virtual Machine.
I hope that Parrot team will be able to make a very fast virtual machine...
Read More 6 comments
Comments: 6