Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Shootout (f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 44 Topic 45754 of 46738
Post > Topic >>

Re: Shootout (fannkuch)

by Isaac Gouy <igouy2@[EMAIL PROTECTED] > May 5, 2008 at 08:27 AM

On May 5, 3:10 am, Branimir Maksimovic <bm...@[EMAIL PROTECTED]
> wrote:
> On May 5, 8:54 am, Razii <tynkf...@[EMAIL PROTECTED]
> wrote:
>
> > On Wed, 30 Apr 2008 08:00:38 -0700 (PDT), Isaac Gouy
>
> > <igo...@[EMAIL PROTECTED]
> wrote:
> > >Why don't you go through all...
>
> > This time I am going to demonstrate a very serious problem with the
> >shootoutsite.
>
> > The algorithms used by C, C++, and D are BETTER than the Java
> > versions! What the heck? In some cases Java version is so bad that
> > it's 10 times slower.


The FAQ gives instructions on how to contribute better programs

http://shootout.alioth.debian.org/gp4/faq.php#play



> Well, I wouldn't be to serious aboutshootoutsite,
> as programs compared are trivial and results vary on
> setup and machine. You can conclude only that
> on particular machine, with particular
> os, with particular setup, results are as they
> are. You can't conclude that results will
> be in same pro****tion on anything else.


Performance measurements are brittle.


> For example on my computer both c and c++ versions
> show same execution time (gcc 4.2.3).
> That should be that way as both are basically same.
> C++ version uses vector instead of raw array and
> also swaps with std function instead of doing it manually.
> But that costs 30% in performance according to site.
> Interesting is that following version of c++ program
> shows 10% increase in performance relative to both c and c++ version
> on the site on my computer ;)
> I only use next_permutation instead of algorithm showed
> in benchmark, and populate arrays in range of 1..n,
> instead of 0..n-1.
> What isn't clear to me is why flips are not performed
> when permutation array has maximum value for last
> element?
>
> #include <iostream>
> #include <iterator>
> #include <vector>
> #include <algorithm>
>
> using namespace std;
>
> struct Inc{
>   int operator()(){ return i_++; }
>   Inc(int i=1):i_(i){}
>   int i_;};
>
> int fannkuch(int n, ostream &o) {
>   if (n < 1) return 0;
>   vector<int> perm(n),flips(n);
>   generate(perm.begin(),perm.end(),Inc());
>   int dispcount=0, maxFlips=0;
>   do
>   {
>     if(dispcount++<30)
>     {
>       copy(perm.begin(),perm.end(),ostream_iterator<int>(o));
>       o<<'\n';
>     }
>     if (!(perm[0]==1 || perm[n-1]==n)) // ?? why
>     {
>       copy(perm.begin(),perm.end(),flips.begin());
>       int nflips=0;
>       while(flips[0]!=1)
>       {
>         reverse(flips.begin(),flips.begin()+flips[0]);
>         ++nflips;
>       }
>       if(nflips>maxFlips)maxFlips=nflips;
>     }
>   }while(next_permutation(perm.begin(),perm.end()));
>   return maxFlips;
>
> }
>
> int main(int argc, const char **argv) {
> int     n = (argc>1) ? atoi(argv[1]) : 0;
> cout << "Pfannkuchen(" << n << ") = "
>  << fannkuch(n, cout) << '\n';
> return 0;
>
> }
>
> Greetings, Branimir.
 




 44 Posts in Topic:
Shootout (fannkuch)
Razii <tynkfghf@[EMAIL  2008-05-05 01:54:16 
Re: Shootout (fannkuch)
Razii <tynkfghf@[EMAIL  2008-05-05 04:03:34 
Re: Shootout (fannkuch)
Razii <tynkfghf@[EMAIL  2008-05-05 04:47:43 
Re: Shootout (fannkuch)
Sherman Pendley <spamt  2008-05-05 05:47:08 
Re: Shootout (fannkuch)
Razii <tynkfghf@[EMAIL  2008-05-05 06:12:14 
Re: Shootout (fannkuch)
Razii <jhgf@[EMAIL PRO  2008-05-05 06:12:34 
Re: Shootout (fannkuch)
Branimir Maksimovic <b  2008-05-05 03:10:37 
Re: Shootout (fannkuch)
Razii <gjtrsds@[EMAIL   2008-05-05 06:51:41 
Re: Shootout (fannkuch)
Isaac Gouy <igouy2@[EM  2008-05-05 08:27:23 
Re: Shootout (fannkuch)
Razii <gjtrsds@[EMAIL   2008-05-05 12:21:00 
Re: Shootout (fannkuch)
Andrea Francia <andrea  2008-05-05 13:06:30 
Re: Shootout (fannkuch)
Joshua Cranmer <Pidgeo  2008-05-05 23:29:50 
Re: Shootout (partialsums)
Razii <gjgjdfyt@[EMAIL  2008-05-05 11:54:29 
Re: Shootout (partialsums)
"Peter Duniho"   2008-05-05 10:11:39 
Re: Shootout (partialsums)
Andrea Francia <andrea  2008-05-05 20:41:48 
Re: Shootout (partialsums)
Razii <jghgg@[EMAIL PR  2008-05-05 17:53:40 
Re: Shootout (partialsums)
Lew <lew@[EMAIL PROTEC  2008-05-05 22:36:40 
Re: Shootout (partialsums)
"kwikius" <a  2008-05-05 19:50:19 
The boogus: Shootout website
Razi<fghfg@[EMAIL PROT  2008-05-21 01:05:21 
Re: The boogus: Shootout website
"kwikius" <a  2008-05-21 09:36:14 
Re: The boogus: Shootout website
Razii <ghrry@[EMAIL PR  2008-05-21 04:29:22 
Re: The boogus: Shootout website
Raz <lpoo@[EMAIL PROTE  2008-05-21 04:43:42 
Re: The boogus: Shootout website
Isaac Gouy <igouy2@[EM  2008-05-21 08:01:45 
Re: The boogus: Shootout website
Razii <gjtrsds@[EMAIL   2008-05-21 12:41:53 
Re: The boogus: Shootout website
Sherman Pendley <spamt  2008-05-21 12:21:59 
Re: The boogus: Shootout website
Razii <jdfd@[EMAIL PRO  2008-05-21 11:40:27 
Re: The boogus: Shootout website
Sherman Pendley <spamt  2008-05-21 14:17:44 
Re: The boogus: Shootout website
Razii <oetka@[EMAIL PR  2008-05-21 13:41:46 
Re: The boogus: Shootout website
Sherman Pendley <spamt  2008-05-21 17:57:33 
Re: The boogus: Shootout website
Razii <jkwwjhy@[EMAIL   2008-05-21 17:17:32 
Re: The boogus: Shootout website
Michael DOUBEZ <michae  2008-05-21 22:20:13 
Re: The boogus: Shootout website
Razii <fghtt@[EMAIL PR  2008-05-21 15:57:18 
Re: The boogus: Shootout website
"kwikius" <a  2008-05-22 00:02:06 
Re: The boogus: Shootout website
Sherman Pendley <spamt  2008-05-21 18:14:36 
Re: The boogus: Shootout website
Razii <rtsall@[EMAIL P  2008-05-21 17:21:12 
Re: The boogus: Shootout website
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-21 19:34:47 
Re: The boogus: Shootout website
Razii <bjtda@[EMAIL PR  2008-05-21 19:10:10 
trig functions (in java and c++)
Raz <rtysjiy@[EMAIL PR  2008-05-21 16:29:09 
Re: trig functions (in java and c++)
"kwikius" <a  2008-05-22 02:13:28 
Re: trig functions (in java and c++)
Razii <gjtrsds@[EMAIL   2008-05-22 02:01:49 
Re: trig functions (in java and c++)
"Default User"   2008-05-22 18:56:46 
Re: trig functions (in java and c++)
Razii <dgdg@[EMAIL PRO  2008-05-22 23:04:31 
Re: The boogus: Shootout website
kwikius <andy@[EMAIL P  2008-05-21 17:16:57 
Re: The boogus: Shootout website
Razii <gjtrsds@[EMAIL   2008-05-21 19:31:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 0:30:53 CDT 2008.