unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mikael Djurfeldt <mikael@djurfeldt.com>
To: Matt Wette <matt.wette@gmail.com>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: Python-on-guile
Date: Sat, 24 Apr 2021 11:43:31 +0200	[thread overview]
Message-ID: <CAA2Xvw+Lht4wm5Z=DDAwnp+rtNDQWMf+XWzKUFtKATUAaSVV2g@mail.gmail.com> (raw)
In-Reply-To: <595a85a2-18df-a548-79d9-d7bbc78cd904@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1131 bytes --]

On my machine, Jython runs 1.4 times slower than python3, that is almost
double the speed of python-on-guile.

I attach the script which can be run by simply typing, e.g.,

  python3 ramanujan20.py

and should print out

  262656

On Fri, Apr 23, 2021 at 11:05 PM Matt Wette <matt.wette@gmail.com> wrote:

> On 4/23/21 8:00 AM, Mikael Djurfeldt wrote:
> > Hi,
> >
> > Yesterday, Andy committed new code to the compiler, some of which
> concerned
> > skipping some arity checking.
> >
> > Also, Stefan meanwhile committed something called "reworked object
> system"
> > to his python-on-guile.
> >
> > Sorry for coming with unspecific information (don't have time to track
> down
> > the details) but I noticed that my benchmark script written in Python,
> and
> > which computes the 20:th Ramanujan number, now runs 60% faster than
> before
> > these changes.
> >
> > This means that python-on-guile running on guile3 master executes python
> > code only 2.6 times slower than the CPython python3 interpreter itself.
> :-)
> >
> > Have a nice weekend all,
> > Mikael
> A fun comparison might be python-on-guile3 vs Jython.
>
>
>
>

[-- Attachment #2: ramanujan20.py --]
[-- Type: text/x-python, Size: 1725 bytes --]

#!/usr/bin/python3

#  ramanujan.py -- Compute the N:th Ramanujan number
#  
#  Copyright (C) 2018-2021 Mikael Djurfeldt
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Version 2

# return the N:th Ramanujan number (sum of two cubes in more than one way)
#
def ramanujan (n):
    w = 0 # Ramanujan number candidate
    b0 = 1 # first second term to try
    while n > 0:
        w += 1 # try next candidate

        # increase initial b0 until 1 + b0^3 >=w
        while 1 + b0 * b0 * b0 < w:
            b0 += 1
            
        a = 1
        a3 = 1
        b = b0
        b3 = b0 * b0 * b0
        count = 0 # number of ways to write w
        while a <= b:
            s = a3 + b3
            if s < w:
                a += 1 # if sum is too small, increase a
                a3 = a * a * a
                continue
            elif s == w:
                count += 1 # found a sum!
                if count > 1:
                    n -= 1
                    break
            b -= 1 # increase b both if sum too large and to find next way to write w
            b3 = b * b * b
    return w

print (ramanujan (20))

  reply	other threads:[~2021-04-24  9:43 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 15:00 Python-on-guile Mikael Djurfeldt
2021-04-23 20:35 ` Python-on-guile Zelphir Kaltstahl
2021-04-23 20:41 ` Python-on-guile Linus Björnstam
2021-04-23 21:04 ` Python-on-guile Matt Wette
2021-04-24  9:43   ` Mikael Djurfeldt [this message]
2021-04-24 10:04 ` Python-on-guile Mikael Djurfeldt
2021-04-24 11:26   ` Python-on-guile Stefan Israelsson Tampe
2021-04-24 12:59     ` Python-on-guile Stefan Israelsson Tampe
2021-04-24 14:41       ` Python-on-guile Stefan Israelsson Tampe
2021-04-24 15:19         ` Python-on-guile Stefan Israelsson Tampe
2021-04-25  8:20           ` Python-on-guile Mikael Djurfeldt
2021-04-25 10:21             ` Python-on-guile Stefan Israelsson Tampe
2021-04-25  8:46           ` Python-on-guile Stefan Israelsson Tampe
2021-04-25 10:54       ` Python-on-guile Dr. Arne Babenhauserheide
2021-04-25 11:54         ` Python-on-guile Vivien Kraus via General Guile related discussions
2021-04-25 10:18 ` Python-on-guile Stefan Israelsson Tampe
2021-04-27 12:29 ` Python-on-guile Nala Ginrut
  -- strict thread matches above, loose matches on Subject: below --
2020-02-09 17:30 python-on-guile david larsson
2020-02-09 17:59 ` python-on-guile Stefan Israelsson Tampe
2020-02-09 19:39   ` python-on-guile david larsson
     [not found]     ` <CAGua6m1aQuwGu4ZRRk9r1Ytao_QjftzCQK5+tb_B4axh-Y3aWg@mail.gmail.com>
     [not found]       ` <CAGua6m1VFHsaid+CGUN==3AvXqZTZUO8xbOSh3r4xNVTAik79g@mail.gmail.com>
     [not found]         ` <CAGua6m3vTY=hk8QaEoKUvFwPsm7N-uatMV1KyvgdAyKS4Gjh9g@mail.gmail.com>
2020-02-10 12:13           ` python-on-guile david larsson
2020-02-10 14:40             ` python-on-guile Stefan Israelsson Tampe
2020-02-10 14:46             ` python-on-guile Stefan Israelsson Tampe
2020-02-10 20:11             ` python-on-guile Stefan Israelsson Tampe
2020-02-11  7:17               ` python-on-guile david larsson
2020-02-11 10:44                 ` python-on-guile Stefan Israelsson Tampe
2020-02-11 20:57                 ` python-on-guile Stefan Israelsson Tampe
2020-02-12  9:18                   ` python-on-guile david larsson
2020-02-12  9:59                     ` python-on-guile Stefan Israelsson Tampe
2020-02-12 15:26                       ` python-on-guile david larsson
     [not found]                         ` <CAGua6m2SP2RZ1Ok5bG2xmoHGanmRUrfaG34yY7P8=AWs0fXw2g@mail.gmail.com>
2020-02-12 19:47                           ` python-on-guile david larsson
     [not found]                             ` <CAGua6m1rcNZT_15LN=dWRb66E93UyLDFfdkaJjmyWYerWE9Jpg@mail.gmail.com>
     [not found]                               ` <46dbd813788cc3d1dc0b994106c8a528@selfhosted.xyz>
     [not found]                                 ` <CAGua6m12ytkdDcHj+PEx615qCzaXPB4P+u-DCqWQexuRo28BWA@mail.gmail.com>
2020-02-13  7:30                                   ` python-on-guile david larsson
     [not found]                                     ` <CAGua6m2+hEpGf8Z+CfyO+-mKH4sQF-mVb7YS1=+88hF2bRkjPw@mail.gmail.com>
2020-02-18 10:45                                       ` python-on-guile david larsson
     [not found]                                         ` <CAGua6m0d=L9b9MEMYekX0tL0PO3k+ZR+LP=7YYQojzr0VYdkmw@mail.gmail.com>
2020-02-19  7:30                                           ` python-on-guile david larsson
2019-07-09 17:15 python-on-guile Stefan Israelsson Tampe
2019-06-14 18:06 python-on-guile Stefan Israelsson Tampe
2019-06-22 21:07 ` python-on-guile Arne Babenhauserheide
2019-06-26 18:45 ` python-on-guile Nala Ginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA2Xvw+Lht4wm5Z=DDAwnp+rtNDQWMf+XWzKUFtKATUAaSVV2g@mail.gmail.com' \
    --to=mikael@djurfeldt.com \
    --cc=guile-user@gnu.org \
    --cc=matt.wette@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).