[kde-solaris] Re: fibonacci

Stefan Teleman steleman at nyc.rr.com
Sat Nov 6 01:53:17 CET 2004


On Friday 05 November 2004 08:07, Eva Brucherseifer wrote:
> ... which doesn't really give a good number ;-)
> CPU architectures and compilers give very different time results,
> if it comes to integer vs. float calculation. KDE is a gui and thus
> you mainly have integer calculation - here calculating PI certainly
> isn't a good benchmark. And don't ask me for a proposal an how to
> measure speed on KDE...
>
> Greetings,
> eva

------

:-)

No doubles, no floating point:

/* fibonacci.c */

#include <stdio.h>
#include <math.h>
#include <time.h>

static const unsigned int iterations = 10;

unsigned int fibonacci (unsigned int n)
{
        return ((n < 2) ? 1 : fibonacci(n-1) + fibonacci(n-2));
}

int
main (int argc, char* argv[])
{
        int i = 0;
        unsigned int j = 0;
        unsigned int result;
        clock_t start;
        clock_t end;
        double elapsed;

        if (argc != 2)
        {
                (void) fprintf (stderr, "Usage: %s <fibonacci>\n", 
argv[0]);
                return (-1);
        }
        i = atoi(argv[1]);
        start = clock();
        for (j = 0; j < iterations; j++)
        {
                result = fibonacci((unsigned int) i);
        }

        end = clock();
        elapsed = ((double) (end / CLOCKS_PER_SEC) - (double) (start / 
CLOCKS_PER_SEC));
        (void) fprintf (stderr, "%s: calculated %u fibonacci(%ld) in 
%lf seconds\n", argv[0], iterations, i, elapsed);
        return (0);
}

/* fibonacci.c */

Downloaded from sunfreeware: GCC 3.4.2

[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:46:08][178]>> 
/usr/local/bin/gcc --version
gcc (GCC) 3.4.2
Copyright (C) 2004 Free Software Foundation, Inc.
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There 
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:46:08][179]>>

[ ... figure out gcc 3.4.2's flags ... ]

[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:49:41][182]>> 
/usr/local/bin/gcc -m32 -mv8plus -O3 fibonacci.c -o fibonacci.gcc342 
-lc -lm
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:49:51][183]>>  
./fibonacci.gcc342 36
./fibonacci.gcc342: calculated 10 fibonacci(36) in 17.000000 seconds
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:50:48][184]>>  
source .cflags 
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:51:23][185]>>  
echo $CC
/opt/Forte-9.0/SUNWspro/prod/bin/cc
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:51:36][186]>> 
echo $CFLAGS
-erroff=%all -errshort=full -errfmt=error -errwarn=%none -xO4 -s 
-xc99=%all,no%lib -xjobs=2 -xtarget=ultra2 -dalign -xprefetch=auto 
-xprefetch_level=3 -xbuiltin=%all -xregs=appl,no%float 
-xcache=32/64/4:2048/64/1 -xcsi -xcode=pic32 -xinline=%auto 
-xustr=ascii_utf16_ushort -xvis=yes -z now -z rescan -z absexec 
-xildoff -xldscope=symbolic -xpagesize=default -xF=%all 
-xalias_level=std -xmemalign=8i -xsafe=mem -xthreadvar -lpthread 
-lposix4 -lrt -mt -D_REENTRANT -D__EXTENSIONS__ -D_XPG4_2 -DSOLARIS 
-DSOLARIS9 -DUSE_SOLARIS -DNDEBUG -KPIC -xarch=v8plusa
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:51:38][187]>>  
$CC $CFLAGS fibonacci.c -o fibonacci.forte9 -lc -lm
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:53:11][188]>> 
> ./fibonacci.forte9 36
./fibonacci.forte9: calculated 10 fibonacci(36) in 9.000000 seconds
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:53:51][189]>> 
uname -a
SunOS obiwan 5.9 Generic_117171-05 sun4u sparc SUNW,Ultra-60
[steleman at obiwan][~/programming/fibonacci][11/05/2004 19:59:28][190]>> 

--Stefan

-- 
Stefan Teleman          'Nobody Expects the Spanish Inquisition'
steleman at nyc.rr.com                          -Monty Python



More information about the kde-solaris mailing list