Listing 2.
elapsed: Using the Wrappered C Function
Scott Bolte

SWIG
The Perl Journal, Winter 1997
  elapsed: Using the Wrappered C Function


#!/usr/bin/perl -w



# Use the first N elements of the Fibonacci sequence 

# to approximate the Golden Mean.



use strict;

use Elapsed;



my $before = Elapsed::elapsed_seconds();



my $N = shift || 20;	 # Take either first argument or 20.

my ($n1, $n2) = (1, 1);



printf("%2d:  %10d\n", 1, $n1);

printf("%2d:  %10d  %.10g\n", 2, $n2, $n2/$n1);



for (3..$N) {

    	($n1, $n2) = ($n2, $n1 + $n2);

    	printf("%2d:  %10d  %.10g\n", $_, $n2, $n2/$n1);

}



my $after = Elapsed::elapsed_seconds();



printf("Elapsed time is %g seconds.\n", 

                                 $after - $before);