Computer Language Shootout

Discussion in 'Python' started by igouy@yahoo.com, Nov 29, 2005.

  1. Guest

    , Nov 29, 2005
    #1
    1. Advertising

  2. Guest

    This is a direct translation of the D code, maybe it's not the faster
    Python implementation, and surely it's not the shorter one. But Psyco
    makes it much faster (Psyco likes "low level" style code).
    ShedSkink is (almost) able to compile it too, producing a really fast
    executable (with some "smart attentions" this SS version becomes only
    17% slower than the D version for a given n=11 (26.66 sec instead of
    22.70 sec of total running time on a PIII 500 MHz)).


    ! import sys
    !
    ! def fannkuch(n):
    ! perm = [0] * n
    ! perm1 = range(n)
    ! count = [0] * n
    ! m = n - 1
    ! r = n
    ! maxFlipsCount = 0
    !
    ! while True:
    ! while r != 1:
    ! count[r-1] = r
    ! r -= 1
    !
    ! # SS v.0.0.5 has a problem with this line:
    ! if not (perm1[0]==0 or perm1[m]==m):
    ! #perm = list(perm1)
    ! # to not produce memory garbage
    ! for i in xrange(n):
    ! perm = perm1
    !
    ! i = perm[0]
    ! flips = 0
    ! while i:
    ! temp = perm
    ! perm = i
    ! i = temp
    ! j = 1
    ! k = i - 1
    ! while j < k:
    ! temp = perm[j]
    ! perm[j] = perm[k]
    ! perm[k] = temp
    ! j += 1
    ! k -= 1
    ! flips += 1
    !
    ! if flips > maxFlipsCount:
    ! maxFlipsCount = flips
    !
    ! while True:
    ! if r == n:
    ! return maxFlipsCount
    ! temp = perm1[0]
    ! i = 0
    ! while i < r:
    ! j = i + 1
    ! perm1 = perm1[j]
    ! i = j
    ! perm1[r] = temp
    !
    ! count[r] -= 1
    ! if count[r] > 0:
    ! break
    ! r += 1
    !
    !
    ! #import psyco
    ! #psyco.bind(fannkuch)
    !
    ! if len(sys.argv) > 1:
    ! n = int(sys.argv[1])
    ! else:
    ! n = 1
    ! print "Pfannkuchen(%d) = %ld" % (n, fannkuch(n))


    Bye,
    bearophile
    , Nov 29, 2005
    #2
    1. Advertising

  3. Guest

    We don't scrape programs from news-groups, if you'd like the program to
    be shown on the shootout then please attach the source code to a
    tracker item.

    Please follow the FAQ instructions
    http://shootout.alioth.debian.org/faq.php#contribute


    wrote:
    > This is a direct translation of the D code, maybe it's not the faster
    > Python implementation, and surely it's not the shorter one. But Psyco
    > makes it much faster (Psyco likes "low level" style code).
    > ShedSkink is (almost) able to compile it too, producing a really fast
    > executable (with some "smart attentions" this SS version becomes only
    > 17% slower than the D version for a given n=11 (26.66 sec instead of
    > 22.70 sec of total running time on a PIII 500 MHz)).
    >
    >
    > ! import sys
    > !
    > ! def fannkuch(n):
    > ! perm = [0] * n
    > ! perm1 = range(n)
    > ! count = [0] * n
    > ! m = n - 1
    > ! r = n
    > ! maxFlipsCount = 0
    > !
    > ! while True:
    > ! while r != 1:
    > ! count[r-1] = r
    > ! r -= 1
    > !
    > ! # SS v.0.0.5 has a problem with this line:
    > ! if not (perm1[0]==0 or perm1[m]==m):
    > ! #perm = list(perm1)
    > ! # to not produce memory garbage
    > ! for i in xrange(n):
    > ! perm = perm1
    > !
    > ! i = perm[0]
    > ! flips = 0
    > ! while i:
    > ! temp = perm
    > ! perm = i
    > ! i = temp
    > ! j = 1
    > ! k = i - 1
    > ! while j < k:
    > ! temp = perm[j]
    > ! perm[j] = perm[k]
    > ! perm[k] = temp
    > ! j += 1
    > ! k -= 1
    > ! flips += 1
    > !
    > ! if flips > maxFlipsCount:
    > ! maxFlipsCount = flips
    > !
    > ! while True:
    > ! if r == n:
    > ! return maxFlipsCount
    > ! temp = perm1[0]
    > ! i = 0
    > ! while i < r:
    > ! j = i + 1
    > ! perm1 = perm1[j]
    > ! i = j
    > ! perm1[r] = temp
    > !
    > ! count[r] -= 1
    > ! if count[r] > 0:
    > ! break
    > ! r += 1
    > !
    > !
    > ! #import psyco
    > ! #psyco.bind(fannkuch)
    > !
    > ! if len(sys.argv) > 1:
    > ! n = int(sys.argv[1])
    > ! else:
    > ! n = 1
    > ! print "Pfannkuchen(%d) = %ld" % (n, fannkuch(n))
    >
    >
    > Bye,
    > bearophile
    , Nov 29, 2005
    #3
  4. On 29 Nov 2005 14:08:12 -0800, wrote:

    >We don't scrape programs from news-groups, if you'd like the program to
    >be shown on the shootout then please attach the source code to a
    >tracker item.

    You asked for something, got a response, and then you haughtily[1] declare
    that it's not being served on a special platter from your cupboard,
    and you won't deign to "scrape" the serving onto your own platter.
    Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.

    Using what you are _given_ in a normal (and voluntary!) response
    __within the same newsgroup context of your own request__ is not
    to "scrape programs from news-groups".

    [1] allowing for possible language translation difficulties resulting
    in expressions with unintended attitudinal overtones.

    If you are not prepared at least to say "thanks" before rejecting
    what's offered, please don't ask for anything from newsgroup volunteers.
    They deserve a better response to their generosity.

    >
    >Please follow the FAQ instructions
    >http://shootout.alioth.debian.org/faq.php#contribute


    That "please" is also too little too late, after the impact of
    your chosen leading phrase (before the first comma).

    >
    >
    > wrote:
    >> This is a direct translation of the D code, maybe it's not the faster
    >> Python implementation, and surely it's not the shorter one. But Psyco

    See how top-posting screws things up? The immediately above is what you
    responded to. Your response and mine (which is in parts interpolated into
    yours below parts of yours the put relevant response below what it is
    responding to) all belong down here. Double-pfui.

    I better eat. I note that I was a bit too easily provoked into this grumpiness ;-)

    Regards,
    Bengt Richter
    Bengt Richter, Nov 30, 2005
    #4
  5. Guest

    Bengt Richter wrote:
    > On 29 Nov 2005 14:08:12 -0800, wrote:
    >
    > >We don't scrape programs from news-groups, if you'd like the program to
    > >be shown on the shootout then please attach the source code to a
    > >tracker item.

    > You asked for something, got a response, and then you haughtily[1] declare
    > that it's not being served on a special platter from your cupboard,
    > and you won't deign to "scrape" the serving onto your own platter.
    > Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.
    >

    I don't see it as an attitude issue but wording. It is blunt but I can
    see his point. He was asking people if it is possible to
    submit(contribute) some code to the test. And based on what I saw on
    his site, it is inappropriate for him to just take code from ML/usenet
    as all codes there need proper author(beyond courtesy, there may be
    copyright issue). That is my reading anyway.

    If it was nicely explained why it needs to be done this way upfront(or
    in the response), I believe you may not feel it this way.

    Interestingly, I find this response quite compatible with the
    personality of this group.
    , Nov 30, 2005
    #5
  6. On 29 Nov 2005 18:34:34 -0800, wrote:

    >
    >Bengt Richter wrote:
    >> On 29 Nov 2005 14:08:12 -0800, wrote:
    >>
    >> >We don't scrape programs from news-groups, if you'd like the program to
    >> >be shown on the shootout then please attach the source code to a
    >> >tracker item.

    >> You asked for something, got a response, and then you haughtily[1] declare
    >> that it's not being served on a special platter from your cupboard,
    >> and you won't deign to "scrape" the serving onto your own platter.
    >> Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.
    >>

    >I don't see it as an attitude issue but wording. It is blunt but I can

    Wording order expresses the attention priorities of the speaker.
    The OP was effectively saying, "I may get around to saying something about
    what you did, but first, here's the way I operate, and what you need to
    adapt to. Please adapt. Now I have no more time to say anything about what you did,
    or to acknowledge it, never mind to express thanks for the effort."

    That's not just blunt and concise, it looks like the modus operandi
    of a typical volunteer/employee-exploiter (or perhaps spoiled brat,
    the typical precursor to the former).

    >see his point. He was asking people if it is possible to
    >submit(contribute) some code to the test. And based on what I saw on
    >his site, it is inappropriate for him to just take code from ML/usenet
    >as all codes there need proper author(beyond courtesy, there may be
    >copyright issue). That is my reading anyway.

    That's possible, but the way I read the OP's post, his priority was
    not exactly expression of gratitude, which IMO was due first.

    >
    >If it was nicely explained why it needs to be done this way upfront(or
    >in the response), I believe you may not feel it this way.

    Exactly. Up front would imply different social priorities, at least to me.
    >
    >Interestingly, I find this response quite compatible with the
    >personality of this group.

    Which "this"? ;-)

    Regards,
    Bengt Richter
    Bengt Richter, Nov 30, 2005
    #6
  7. Guest

    Bengt Richter wrote:
    > >Interestingly, I find this response quite compatible with the
    > >personality of this group.

    > Which "this"? ;-)
    >

    I meant his response.
    , Nov 30, 2005
    #7
  8. malv Guest

    Hi bearophileH,

    Thank you for the code example.
    Could you post some more information about ShedSkink?
    malv
    malv, Nov 30, 2005
    #8
  9. Guest

    wrote:
    > Bengt Richter wrote:
    > > On 29 Nov 2005 14:08:12 -0800, wrote:
    > >
    > > >We don't scrape programs from news-groups, if you'd like the program to
    > > >be shown on the shootout then please attach the source code to a
    > > >tracker item.

    > > You asked for something, got a response, and then you haughtily[1] declare
    > > that it's not being served on a special platter from your cupboard,
    > > and you won't deign to "scrape" the serving onto your own platter.
    > > Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.
    > >

    > I don't see it as an attitude issue but wording. It is blunt but I can
    > see his point. He was asking people if it is possible to
    > submit(contribute) some code to the test. And based on what I saw on
    > his site, it is inappropriate for him to just take code from ML/usenet
    > as all codes there need proper author(beyond courtesy, there may be
    > copyright issue). That is my reading anyway.


    That is correct, we publish an author's work under Revised BSD - we
    can't just take a program from a newsgroup.


    >
    > If it was nicely explained why it needs to be done this way upfront(or
    > in the response), I believe you may not feel it this way.
    >
    > Interestingly, I find this response quite compatible with the
    > personality of this group.
    , Nov 30, 2005
    #9
  10. Fredrik Lundh, Nov 30, 2005
    #10
  11. Bengt Richter wrote:

    > That's not just blunt and concise, it looks like the modus operandi
    > of a typical volunteer/employee-exploiter (or perhaps spoiled brat,
    > the typical precursor to the former).


    careful. his faq requires you to "be nice".

    </F>
    Fredrik Lundh, Nov 30, 2005
    #11
  12. Guest

    malv:

    >Hi bearophileH,


    bearophile is enough :)


    >Could you post some more information about ShedSkink?


    ShedSkin (SS) is a Python -> C++ compiler (or translator) written in
    Python, created by Mark Dufour. Its development was initially
    "financed" by the summer of code by Google. It contains some smart
    algorithms that allow it to infer the type of most variables, and to
    compile everything statically (but with a garbage collector). This
    produces a very fast executable, usually like a C++ one. SS has some
    limits, some of them are temporary, and some of them are here to stay
    (it cannot be used on really dynamic stuff). It's not intended to
    compile every Python program, but mostly for "algorithmic" code that
    has to go fast, often the same code Psyco is used for. It can be seen
    as complementary to Psyco, and not really like something to substitute
    it, Psyco is a very good software. I am helping Mark as I can, in
    different ways, because I think SS is a very interesting software. At
    the moment SS is in the Alpha stage still, this means:
    - It has a lot of bugs still, but Mark fixes some of them almost every
    week. That problem in that fannkuch code is relative to the version
    0.0.5, a successive version may compile it correctly.
    - Some common things aren't possible yet, like inheritance, but Mark is
    probably going to implement this in the following days.
    - The code produced is C++, and it calls functions of the SS library.
    CPython source code contains some very fast routines (by Raymond
    Hettinger and other people), so sometimes CPython is faster (example:
    sometimes Python dicts are faster). This is mostly a
    "tuning/implementation" problem, it's not a limit of SS or the C++ and
    its compiler. It's a matter of knowing lot of complex C++ "tricks" and
    implementing/copying faster routines. Another developer can probably
    help Mark improve most of those algorithms (I think that sometimes the
    CPython source code itself may be adapted and used).
    - If another developer helps Mark, a future version of SS can probably
    be used to automatically produce compiled modules that can be imported
    into normal Python programs (it may call something like SIP/SWIG by
    itself), a very simple single-click command can be used (on Windows in
    a contex menu). The info about the input types of the functions/methods
    may be expressed with some very simple syntax inside the module
    docstring, or simply it may be contained in the part of the module that
    isn't executed when then module is called.
    - There are lot of ways to improve SS still, some people in the Blender
    group have already shown interest in SS, but it contains too much bugs
    still to be used in serious projects. Helping hands can speed up its
    development a lot.

    The project on Sourceforge, it contains more information and
    documentation:
    http://sourceforge.net/projects/shedskin/

    SS blog:
    http://shed-skin.blogspot.com/

    The last version is 0.0.5.1, it contains an important memory bugfix and
    other minor bugfixings.

    Some timings for version 0.0.5:
    http://sourceforge.net/mailarchive/forum.php?thread_id=9040577&forum_id=46397
    (small_dict_fp test is probably faster in version 0.0.5.1).

    Bear hugs,
    bearophile
    , Nov 30, 2005
    #12
  13. Guest

    , Nov 30, 2005
    #13
  14. Guest

    Fredrik Lundh wrote:
    > Bengt Richter wrote:
    >
    > > That's not just blunt and concise, it looks like the modus operandi
    > > of a typical volunteer/employee-exploiter (or perhaps spoiled brat,
    > > the typical precursor to the former).

    >
    > careful. his faq requires you to "be nice".
    >
    > </F>


    "Be Nice!" *is* one of paragraph headings in the FAQ section "How can I
    help?"

    imo Saying that the FAQ "requires you to "be nice" is a
    misrepresentation.
    , Nov 30, 2005
    #14
  15. wrote:

    > "Be Nice!" *is* one of paragraph headings in the FAQ section "How can I
    > help?"


    yeah, we've noticed that it's not one of the headings in the FAQ section
    "How can we encourage you to contribute".

    </F>
    Fredrik Lundh, Nov 30, 2005
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob Lee

    code for Computer Language Shootout

    Jacob Lee, Mar 16, 2005, in forum: Python
    Replies:
    14
    Views:
    631
  2. Delaney, Timothy C (Timothy)

    RE: code for Computer Language Shootout

    Delaney, Timothy C (Timothy), Mar 16, 2005, in forum: Python
    Replies:
    3
    Views:
    311
    Raymond Hettinger
    Mar 17, 2005
  3. Phil Tomson
    Replies:
    25
    Views:
    310
    Gawnsoft
    Jun 20, 2004
  4. Isaac Gouy
    Replies:
    0
    Views:
    112
    Isaac Gouy
    Aug 3, 2004
  5. Replies:
    9
    Views:
    193
    Isaac Gouy
    Mar 29, 2005
Loading...

Share This Page