unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: Mikael Djurfeldt <mikael@djurfeldt.com>
Cc: guile-user <guile-user@gnu.org>, guile-devel <guile-devel@gnu.org>
Subject: Re: Python-on-guile
Date: Sat, 24 Apr 2021 17:19:25 +0200	[thread overview]
Message-ID: <CAGua6m1eiapj5DV8Y0aKOxCtaPQVmU=YPwioBwyLLLstap--cw@mail.gmail.com> (raw)
In-Reply-To: <CAGua6m20-XXDyoYvo7V8iXPn33chFTzjG=+DzRCXpESvRTOX7w@mail.gmail.com>

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

Guile is 3x faster then fastest python-on-guile which is 2x faster then
python3 Cpython

attached is a guile corresponding program.

On Sat, Apr 24, 2021 at 4:41 PM Stefan Israelsson Tampe <
stefan.itampe@gmail.com> wrote:

> To note is that 'continue' is killing performance for python-on-guile
> programs, so by changing the
> code to not use continue lead to python-on-guile running twice the speed
> of python3. The reason is that
> the while loop is used as
> (while (...)
>    (let/ec continue
>         ...))
>
> And the let/ec is probably not optimally compiled. Python-on-guile will
> check the loop for continue usage and if not then it will skip the let/ec.
>
> I attached the code not using continue
>
> On Sat, Apr 24, 2021 at 2:59 PM Stefan Israelsson Tampe <
> stefan.itampe@gmail.com> wrote:
>
>> Actually changing in (language python compile),
>>
>> (define (letec f)
>>   (let/ec x (f x))))
>>
>> To
>>
>> (define-syntax-rule (letec f)
>>   (let/ec x (f x))))
>>
>> Actually lead to similar speeds as python3.
>>
>>
>>
>> On Sat, Apr 24, 2021 at 1:26 PM Stefan Israelsson Tampe <
>> stefan.itampe@gmail.com> wrote:
>>
>>> Pro tip, when running this on guile the scheme code that it compilse to
>>> is located in log.txt.
>>> If you ,opt the resulting code in a guile session you might be able to
>>> pinpoint issues that
>>> delays the code execution.
>>>
>>> On Sat, Apr 24, 2021 at 12:04 PM Mikael Djurfeldt <mikael@djurfeldt.com>
>>> wrote:
>>>
>>>> (I should perhaps add that my script doesn't benchmark the object
>>>> system but rather loops, conditionals and integer arithmetic.)
>>>>
>>>> Den fre 23 apr. 2021 17:00Mikael Djurfeldt <mikael@djurfeldt.com>
>>>> skrev:
>>>>
>>>>> 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
>>>>>
>>>>>

[-- Attachment #2: ram.scm --]
[-- Type: text/x-scheme, Size: 1125 bytes --]

(define (ramanujan  n)
  (let lp ((w 0) (b0 1) (n n))
    (if (> n 0)
        (let ((w (+ w 1)))
          (let lp2 ((b0 b0))
            (if (< (+ 1 (* b0 b0 b0)) w)
                (lp2 (+ b0 1))
                (let lp3 ((a 1) (a3 1) (b b0) (b3 (* b0 b0 b0)) (count 0))
                  (if (<= a b)
                      (let ((s (+ a3 b3)))
                        (cond
                         ((< s w)
                          (let ((aa (+ a 1)))
                            (lp3 aa (* aa aa aa) b b3 count)))
                         ((= s w)
                          (let ((count (+ count 1)))
                            (if (> count 1)
                                (lp w b0 (- n 1))
                                (let* ((b   (- b 1))
                                       (b3  (* b b b)))
                                  (lp3 a a3 b b3 count)))))
                         (else
                          (let* ((b   (- b 1))
                                 (b3  (* b b b)))
                            (lp3 a a3 b b3 count)))))
                      (lp w b0 n))))))
        w)))

(pk (ramanujan 20))

  reply	other threads:[~2021-04-24 15:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 15:00 Python-on-guile Mikael Djurfeldt
2021-04-23 20:41 ` Python-on-guile Linus Björnstam
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         ` Stefan Israelsson Tampe [this message]
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 --
2022-02-19 19:36 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='CAGua6m1eiapj5DV8Y0aKOxCtaPQVmU=YPwioBwyLLLstap--cw@mail.gmail.com' \
    --to=stefan.itampe@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=mikael@djurfeldt.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).