www.digitalmars.com         C & C++   DMDScript  

c++ - Computing Fibonacci numbers as a performance testsuite

reply "Alex Vinokur" <alexvn connect.to> writes:
An algorithm which computes very long Fibonacci numbers
  http://groups.google.com/groups?selm=bnni5p%2412i47o%241%40ID-79865.news.uni-berlin.de
  was used as a performance testsuite
  to compare speed of the code produced by various compilers.


===========================================================
Windows 2000 Professional Ver 5.0 Build 2195 Service Pack 2
Intel(R) Celeron(R) CPU 1.70 GHz
GNU time 1.7 (to get the real time used)
===========================================================


A. Real and processor time used to compute Fibonacci[10000] and
Fibonacci[25000].

   Here are summary results.

|=========================================================
|                      | Opt |  Fib-10000  |  Fib-25000  |
|       Compiler       | Lev |-------------|-------------|
|                      |     | Real : CPU  | Real : CPU  |
|========================================================|
|                    GNU gcc compiler                    |
|--------------------------------------------------------|
| g++ 3.3.1 (Cygwin)   | No  | 0.45 : 0.41 | 1.86 : 1.81 |
|                      | O1  | 0.28 : 0.24 | 1.03 : 0.99 |
|                      | O2  | 0.27 : 0.23 | 1.02 : 0.98 |
|                      | O3  | 0.27 : 0.24 | 1.02 : 0.98 |
|                      |     |      :      |      :      |
| g++ 3.3.1 (Cygwin)   | No  | 0.33 : 0.30 | 1.59 : 1.56 |
| Mingw32 interface    | O1  | 0.20 : 0.16 | 0.87 : 0.84 |
|                      | O2  | 0.19 : 0.16 | 0.85 : 0.82 |
|                      | O3  | 0.19 : 0.16 | 0.85 : 0.82 |
|                      |     |      :      |      :      |
| gpp 3.2.1 (DJGPP)    | No  | 0.37 : 0.24 | 1.99 : 1.92 |
|                      | O1  | 0.20 : 0.11 | 1.15 : 1.05 |
|                      | O2  | 0.19 : 0.11 | 1.08 : 0.99 |
|                      | O3  | 0.19 : 0.11 | 1.08 : 0.99 |
|                      |     |      :      |      :      |
|--------------------------------------------------------|
|       Digital Mars C/C++ Compiler, STLport 4.5.3       |
|--------------------------------------------------------|
| Version 8.35n        | -   | 0.20 : 0.16 | 0.84 : 0.80 |
|                      |     |      :      |      :      |
| Version 8.36.4n      | -   | 0.20 : 0.16 | 0.84 : 0.80 |
|=========================================================



B. The names of DLL files on which the programs depend :

   * g++ 3.3.1 (Cygwin)
     ------------------
     C:\cygwin\bin\cygwin1.dll
       C:\WINNT\System32\KERNEL32.dll
         C:\WINNT\System32\NTDLL.DLL


   * g++ 3.3.1 (Cygwin, Mingw32 interface)
     -------------------------------------
      C:\WINNT\System32\msvcrt.dll
        C:\WINNT\System32\KERNEL32.dll
          C:\WINNT\System32\NTDLL.DLL


   * gpp 3.2.1 (DJGPP)
     -----------------
     Unknown


   * Digital Mars C/C++ 8.35n
     ------------------------
     C:\WINNT\System32\KERNEL32.DLL
       C:\WINNT\System32\NTDLL.DLL
     C:\WINNT\System32\USER32.DLL
       C:\WINNT\System32\GDI32.DLL



C. Notes.
     Note-1. The main() program in
             http://groups.google.com/groups?selm=bnni5p%2412i47o%241%40ID-79865.news.uni-berlin.de
             was slightly changed to get the processor time used.

     // ------ Updated main() : BEGIN ------
     #include <time.h>   // Added
     int main (int argc, char **argv)
     {
     const string option (check (argc, argv));
       if (option.empty())
       {
         usage (argv);
         return 1;
       }

     const uint N = atoi (argv[2]);

     const clock_t clock_start = clock();       // Added
       assert (clock_start != clock_t (-1));    // Added

       if (option == ALL_FIBS)
       {
         Fibonacci fib(N);
         fib.show_all_numbers();
       }

       if (option == TH_FIB)
       {
         Fibonacci fib(N);
         fib.show_last_number();
       }

       if (option == SOME_FIBS)
       {
         Fibonacci fib;
         for (int i = 2; i < argc; i++) fib.show_number (atoi(argv[i]));
       }

       if (option == RAND_FIBS)
       {
         const int max_rand_fib = (argc == 3) ? MAX_RAND_FIB : atoi (argv[3]);
         Fibonacci fib;
         for (uint i = 0; i < N; i++) fib.show_number (rand()%max_rand_fib);
       }

       // ------ Added : BEGIN ------
     const clock_t clock_end = clock();
       assert (clock_end != clock_t (-1));

       cerr << "CPU  time used : " << (double (clock_end -
clock_start)/CLOCKS_PER_SEC) << " sec" << endl;
       // ------ Added : END --------

       return 0;
     }
     // ------ Updated main() : END --------



  Note-2. To get the real time used the time() utility was used.



D. Comment.
     It seems that there is some inconsistency between real-time and CPU-time
     while computing Fibonacci [10000] through the DJGPP gpp compiler :
     CPU-time is too small with regard to real-time.
     Probably that might be caused by too small CLOCKS_PER_SEC value (91).
     Note. In Cygwin, MinGW, Digital Mars : CLOCKS_PER_SEC = 1000.



--
 =====================================
   Alex Vinokur
     mailto:alexvn connect.to
     http://mathforum.org/library/view/10978.html
     news://news.gmane.org/gmane.comp.lang.c++.perfometer
   =====================================
Oct 29 2003
parent reply "Alex Vinokur" <alexvn connect.to> writes:
"Alex Vinokur" <alexvn connect.to> wrote in message
news:bnoa4v$38b$1 digitaldaemon.com...
 An algorithm which computes very long Fibonacci numbers
   http://groups.google.com/groups?selm=bnni5p%2412i47o%241%40ID-79865.news.uni-berlin.de
   was used as a performance testsuite
   to compare speed of the code produced by various compilers.


 ===========================================================
 Windows 2000 Professional Ver 5.0 Build 2195 Service Pack 2
 Intel(R) Celeron(R) CPU 1.70 GHz
 GNU time 1.7 (to get the real time used)
 ===========================================================
[snip] Real and processor time used to compute * Fibonacci[10000], * Fibonacci[25000], * Fibonacci[50000] has been measured. Here are summary results. |========================================================================| | | Opt | Fib-10000 | Fib-25000 | Fib-50000 | | Compiler | Lev |-------------|-------------|---------------| | | | Real : CPU | Real : CPU | Real : CPU | |========================================================================| | GNU gcc compiler | |------------------------------------------------------------------------| | g++ 3.3.1 (Cygwin) | No | 0.45 : 0.41 | 1.86 : 1.81 | 6.63 : 6.58 | | | O1 | 0.28 : 0.24 | 1.03 : 0.99 | 3.87 : 3.60 | | | O2 | 0.27 : 0.23 | 1.02 : 0.98 | 3.79 : 3.73 | | | O3 | 0.27 : 0.24 | 1.02 : 0.98 | 3.81 : 3.74 | | | | : | : | : | | g++ 3.3.1 (Cygwin) | No | 0.33 : 0.30 | 1.59 : 1.56 | 5.71 : 5.66 | | Mingw32 interface | O1 | 0.20 : 0.16 | 0.87 : 0.84 | 3.02 : 2.97 | | | O2 | 0.19 : 0.16 | 0.85 : 0.82 | 2.97 : 2.91 | | | O3 | 0.19 : 0.16 | 0.85 : 0.82 | 2.98 : 2.93 | | | | : | : | : | | gpp 3.2.1 (DJGPP) | No | 0.37 : 0.24 | 1.99 : 1.92 | 10.53 : 10.42 | | | O1 | 0.20 : 0.11 | 1.15 : 1.05 | 7.48 : 7.37 | | | O2 | 0.19 : 0.11 | 1.08 : 0.99 | 7.23 : 7.12 | | | O3 | 0.19 : 0.11 | 1.08 : 0.99 | 7.25 : 7.12 | | | | : | : | : | |------------------------------------------------------------------------| | Digital Mars C/C++ Compiler, STLport 4.5.3 | |------------------------------------------------------------------------| | Version 8.35n | - | 0.20 : 0.16 | 0.84 : 0.80 | 3.82 : 3.74 | |========================================================================| -- ===================================== Alex Vinokur mailto:alexvn connect.to http://mathforum.org/library/view/10978.html news://news.gmane.org/gmane.comp.lang.c++.perfometer =====================================
Oct 30 2003
parent reply Heinz Saathoff <hsaat bre.ipnet.de> writes:
Alex Vinokur schrieb...
    Here are summary results.
 
 |========================================================================|
 |                      | Opt |  Fib-10000  |  Fib-25000  |   Fib-50000   |
 |       Compiler       | Lev |-------------|-------------|---------------|
 |                      |     | Real : CPU  | Real : CPU  | Real  :  CPU  |
 |========================================================================|
 |                            GNU gcc compiler                            |
 |------------------------------------------------------------------------|
 | g++ 3.3.1 (Cygwin)   | No  | 0.45 : 0.41 | 1.86 : 1.81 |  6.63 :  6.58 |
 |                      | O1  | 0.28 : 0.24 | 1.03 : 0.99 |  3.87 :  3.60 |
 |                      | O2  | 0.27 : 0.23 | 1.02 : 0.98 |  3.79 :  3.73 |
 |                      | O3  | 0.27 : 0.24 | 1.02 : 0.98 |  3.81 :  3.74 |
 |                      |     |      :      |      :      |       :       |
 | g++ 3.3.1 (Cygwin)   | No  | 0.33 : 0.30 | 1.59 : 1.56 |  5.71 :  5.66 |
 | Mingw32 interface    | O1  | 0.20 : 0.16 | 0.87 : 0.84 |  3.02 :  2.97 |
 |                      | O2  | 0.19 : 0.16 | 0.85 : 0.82 |  2.97 :  2.91 |
 |                      | O3  | 0.19 : 0.16 | 0.85 : 0.82 |  2.98 :  2.93 |
 |                      |     |      :      |      :      |       :       |
 | gpp 3.2.1 (DJGPP)    | No  | 0.37 : 0.24 | 1.99 : 1.92 | 10.53 : 10.42 |
 |                      | O1  | 0.20 : 0.11 | 1.15 : 1.05 |  7.48 :  7.37 |
 |                      | O2  | 0.19 : 0.11 | 1.08 : 0.99 |  7.23 :  7.12 |
 |                      | O3  | 0.19 : 0.11 | 1.08 : 0.99 |  7.25 :  7.12 |
 |                      |     |      :      |      :      |       :       |
 |------------------------------------------------------------------------|
 |               Digital Mars C/C++ Compiler, STLport 4.5.3               |
 |------------------------------------------------------------------------|
 | Version 8.35n        | -   | 0.20 : 0.16 | 0.84 : 0.80 |  3.82 :  3.74 |
 |========================================================================|
^^^^^ Did you supply any optimization switches to DM? Maybe you can run the program without optimization, with switch -o+speed and -o+all ? - Heinz
Oct 31 2003
next sibling parent reply "Alex Vinokur" <alexvn connect.to> writes:
"Heinz Saathoff" <hsaat bre.ipnet.de> wrote in message
news:MPG.1a0cab0bf20ce2289896d5 news.digitalmars.com...
[snip]
 Did you supply any optimization switches to DM? Maybe you can run the
 program without optimization, with switch -o+speed and -o+all ?
[snip] Yes, I do. Here is a new report. Testsuite : Computing very long Fibonacci numbers Source : http://groups.google.com/groups?selm=bo4nls%2417vfq6%241%40ID-79865.news.uni-berlin.de Metrics * Real time - Elapsed (wall clock) time (seconds) * CPU time - Processor time used (seconds) Environment * Windows 2000 Professional Ver 5.0 Build 2195 Service Pack 2 * Intel(R) Celeron(R) CPU 1.70 GHz * GNU time 1.7 (to get the real time) Report-1.1 ============================================================================== | | Opt. | Fib-10000 | Fib-25000 | Fib-50000 | | Compiler | Level |---------------|---------------|---------------| | | | Real : CPU | Real : CPU | Real : CPU | |============================================================================| | GNU gcc compiler | |----------------------------------------------------------------------------| | | | : | : | : | | g++ 3.3.1 (Cygwin) | None | 0.49 : 0.42 | 1.90 : 1.84 | 6.91 : 6.79 | | | O1 | 0.32 : 0.24 | 1.07 : 1.00 | 3.93 : 3.87 | | | O2 | 0.31 : 0.23 | 1.05 : 0.98 | 3.88 : 3.80 | | | O3 | 0.31 : 0.24 | 1.05 : 0.99 | 3.88 : 3.79 | | | | : | : | : | | g++ 3.3.1 (Cygwin) | None | 0.39 : 0.30 | 1.64 : 1.58 | 5.81 : 5.75 | | Mingw32 Interface | O1 | 0.24 : 0.16 | 0.91 : 0.85 | 3.10 : 3.05 | | | O2 | 0.23 : 0.17 | 0.89 : 0.84 | 3.03 : 2.98 | | | O3 | 0.26 : 0.16 | 0.90 : 0.84 | 3.04 : 2.99 | | | | : | : | : | | gpp 3.3.2 (DJGPP) | None | 0.48 : 0.31 | 2.07 : 1.92 | 11.17 : 11.01 | | | O1 | 0.24 : 0.13 | 1.17 : 1.06 | 7.86 : 7.75 | | | O2 | 0.25 : 0.13 | 1.16 : 1.04 | 7.74 : 7.58 | | | O3 | 0.25 : 0.13 | 1.19 : 1.10 | 7.90 : 7.80 | | | | : | : | : | |----------------------------------------------------------------------------| | GNU gcc compiler, STLport 4.5.3 | | Proposed and supported by Gerrit P. Haase | |----------------------------------------------------------------------------| | g++ 3.3.1 (Cygwin) | None | 0.45 : 0.36 | 1.44 : 1.37 | 5.16 : 5.06 | | STLport 4.5.3 | O1 | 0.32 : 0.21 | 0.95 : 0.89 | 3.47 : 3.39 | | | O2 | 0.29 : 0.21 | 0.98 : 0.92 | 3.58 : 3.49 | | | O3 | 0.30 : 0.22 | 1.01 : 0.95 | 3.67 : 3.60 | | | | : | : | : | |----------------------------------------------------------------------------| | Digital Mars C/C++ Compiler, STLport 4.5.3 | |----------------------------------------------------------------------------| | DMC Version 8.35n | None | 0.28 : 0.16 | 0.89 : 0.81 | 3.87 : 3.80 | | STLport 4.5.3 | Speed | 0.25 : 0.14 | 0.78 : 0.70 | 3.44 : 3.37 | | | Space | 0.23 : 0.14 | 0.75 : 0.68 | 3.41 : 3.31 | | | | : | : | : | ============================================================================== Compilation =========== * g++ 3.3.1, Cygwin ----------------- g++ -W -Wall foo.cpp [Optimize Option] -o foo.exe * g++ 3.3.1, Cygwin, Mingw32 interface ------------------------------------ g++ -W -Wall -mno-cygwin foo.cpp [Optimize Option] -o foo.exe * g++ 3.3.1, Cygwin, STLport 4.5.3 -------------------------------- g++ -W -Wall foo.cpp -I/STLport-4.5.3/stlport /lib/libstlport_cygwin.a [Optimize Option] -o foo.exe * gpp 3.3.2, DJGPP ---------------- gpp -W -Wall foo.cpp [Optimize Option] -o foo.exe * Digital Mars C/C++ 8.35n, STLport 4.5.3 --------------------------------------- dmc [Optimize Option] -I. -IC:/dm/stlport/stlport foo.cpp -ofoo.exe The names of DLL files on which the programs depend =================================================== * g++ 3.3.1, Cygwin ----------------- C:\cygwin\bin\cygwin1.dll C:\WINNT\System32\KERNEL32.dll C:\WINNT\System32\NTDLL.DLL * g++ 3.3.1, Cygwin, Mingw32 interface ------------------------------------ C:\WINNT\System32\msvcrt.dll C:\WINNT\System32\KERNEL32.dll C:\WINNT\System32\NTDLL.DLL * g++ 3.3.1, Cygwin, STLport 4.5.3 -------------------------------- C:\cygwin\bin\cygwin1.dll C:\WINNT\System32\KERNEL32.dll C:\WINNT\System32\NTDLL.DLL * gpp 3.3.2, DJGPP ---------------- DJGPP doesn't support dynamic linking. * Digital Mars C/C++ 8.35n, STLport 4.5.3 --------------------------------------- C:\WINNT\System32\KERNEL32.DLL C:\WINNT\System32\NTDLL.DLL C:\WINNT\System32\USER32.DLL C:\WINNT\System32\GDI32.DLL -- ====================================================== Alex Vinokur mailto:alexvn connect.to http://mathforum.org/library/view/10978.html news://news.gmane.org/gmane.comp.lang.c++.perfometer ======================================================
Nov 03 2003
parent Heinz Saathoff <hsaat bre.ipnet.de> writes:
Alex Vinokur wrote...
 [snip]
 Did you supply any optimization switches to DM? Maybe you can run the
 program without optimization, with switch -o+speed and -o+all ?
[snip] Yes, I do. Here is a new report.
[snip]
 |----------------------------------------------------------------------------|
 |                 Digital Mars C/C++ Compiler, STLport 4.5.3                 |
 |----------------------------------------------------------------------------|
 | DMC Version 8.35n  | None  |  0.28 :  0.16 |  0.89 :  0.81 |  3.87 :  3.80 |
 | STLport 4.5.3      | Speed |  0.25 :  0.14 |  0.78 :  0.70 |  3.44 :  3.37 |
 |                    | Space |  0.23 :  0.14 |  0.75 :  0.68 |  3.41 :  3.31 |
 |                    |       |       :       |       :       |       :       |
 ==============================================================================
Interestingly the performance of space optimization is better than speed optimization. - Heinz
Nov 04 2003
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
How about -ffast-math on GCC? It should omit errno then. I wonder if it 
gets any faster or not.

Heinz Saathoff wrote:
 Did you supply any optimization switches to DM? Maybe you can run the 
 program without optimization, with switch -o+speed and -o+all ?
 
 - Heinz
Nov 03 2003