Post Reply 
Python Speed
04-21-2021, 07:34 AM (This post was last modified: 04-21-2021 07:39 AM by toml_12953.)
Post: #1
Python Speed
The new Python interpreter graphics are fast!

I ran three programs to draw a green hat, Here are the runtimes:

HPPL: 7.793 sec
CAS with Python syntax: 25.436 sec
Python (Apr 16 Beta): 0.926 sec

Here's the Python version:
Code:
#PYTHON EXPORT pyhat
from hpprime import *
from math import *
t0 = eval("ticks()") # Save the current clock count for timing program
# Clear screen
fillrect(0,0,0,320,240,0,0)
# Start program proper
p=160; q=120
xp=144; xr=1.5*3.1415927
yp=56; yr=1; zp=64
xf=xr/xp; yf=yp/yr; zf=xr/zp
for zi in range(-q,q+1):
  if zi>=-zp and zi<=zp:
    zt=zi*xp/zp; zz=zi
    xl=int(.5+sqrt(xp*xp-zt*zt))
    # Draw one cross-section of figure
    for xi in range(-xl,xl+1):
      xt=sqrt(xi*xi+zt*zt)*xf; xx=xi
      yy=(sin(xt)+.4*sin(3*xt))*yf
      x1=xx+zz+p
      y1=yy-zz+q
      pixon(0,x1,230-y1,65280)
      if y1!=0:
        line(0,x1,230-y1+1,x1,230,0) # Erase points below current point
t = eval("ticks()")-t0
# Wait for key and print elapsed time
eval("wait()")
t = t/1000
print(t," seconds")
#end

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Python Speed - toml_12953 - 04-21-2021 07:34 AM
RE: Python Speed - robmio - 04-21-2021, 12:05 PM
RE: Python Speed - toml_12953 - 04-21-2021, 01:46 PM
RE: Python Speed - robve - 04-21-2021, 03:14 PM
RE: Python Speed - Xorand - 04-21-2021, 05:10 PM
RE: Python Speed - toml_12953 - 04-22-2021, 06:26 PM
RE: Python Speed - Guenter Schink - 04-22-2021, 06:41 PM



User(s) browsing this thread: 1 Guest(s)