[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Performance: C contra Ada [OffTopic]







Microsoft Visual Studio .Net kompileret C++-kode på mswin32 er langt
hurtigere end både Java og C++ på linux!!!!


Jeg har med vilje kompileret eksemplet med Leonardo fra Pisa aka. Fibonacci
med Visual Studio 7 aka. .Net

Den giver nemlige nogle meget gode pointer omkring kompiler-optimering af
kode


Morten Sylvest Olsen <sslug@sslug> wrote on 06-03-2004
18:28:31:

> On Tue, 02 Mar 2004 17:16:53 +0100, Jakob Oestergaard wrote:
>
> long long doRecTail(const long long  n, long long sum)
> {
>   if (n < 2)
>     return 1 + sum;
>   else {
>     long long tmp = doRecTail(n-1,0);
>     return doRecTail(n - 2, tmp + sum);
>   }
> }

Jeg tillod mig at ændre koden til
long long doRecTail(const long long  n, long long sum)
{
  if (n < 2)
    return sum + 1; // ren paranoia
  else {
    long long tmp = doRecTail(n-1,0);
    return doRecTail(n - 2, tmp + sum);
  }
}

kompilerede og kørte
int main(int, char**)
{
  using namespace std;
  nlj::performance_timer timer
  timer.start();
  cout << doRecTail(40, 0) << endl;
  timer.stop();
  cout << timer.elapsed() << endl;
}
D:\devl\sandkasse\fibonaci\my>fib
165580141
4.83016


herefter ændrede jeg doRecTail lidt til
long long doRecTail(const long long n, long long sum)
{
  if (n < 2)
    return sum + 1;
  else {
    return doRecTail(n - 1, doRecTail(n - 2, sum));
  }
}
D:\devl\sandkasse\fibonaci\my>fib
165580141
3.97652

Da det jo ikke er fair at medtage tiden det tager det tager at udskrive
resultatet ændrede jeg main
int main(int, char**)
{
  using namespace std;
  long long tmp;
  nlj::performance_timer timer
  timer.start();
  tmp= doRecTail(40, 0);
  timer.stop();
  cout << tmp << endl;
  cout << timer.elapsed() << endl;
}
D:\devl\sandkasse\fibonaci\my>fib
165580141
1.67619e-006

Hvis jeg bruger en clock timer bliver tidsforbruget 0.00 (sic!)
.Net kompileren er jo ikke dum -- den kan jo godt gennemskue at res er en
unødvendig temporær variabel der kan optimieres væk -- bytter man om på de
to udskrifter få man at vide at beregnigen tog 0 sekunder -- 4 sekunder
senere får man så resultatet.

Med en Microsoft Performance Timer kan linux ikke måle sig.


                                                                       
                                                                       
                                                                       
 Senior                                   IntraVision                  
 Developer                                                             
                                                                       
                                                                       
                                                                       
 Mail:          sslug@sslug        Lyngsø Alle 3,             
                                          2970 Hørsholm,             
                                          Denmark                      
                                                                       
 Direct:        +45 7023 2340             Office:        +45 7023 2340 
                                                                       
 Mobile:        +45 2613 9966             Fax:           +45 7023 2349 
                                                                       
                                          Web:           www.intravision.dk
                                                                       
                                                                       
                                                                       



This e-mail may contain confidential information and is intended only for
the addressee. If you have received this e-mail by mistake, please notify
the sender and delete this mail.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *