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.we...@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. > > > >
#!/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))