Thanks for trying it and for the encouragement. No, I tested both without gzip. With gzip my script serves it in about 200ms. I didn't try the gzipped version with picoweb. Using the uncompressed test file that I posted, I am consistently getting about two seconds load time with ws and about 15 seconds with picoweb. It seems to run a faster with the ESP8266 in STA mode rather than AP mode. If I disable native code in my script--or use more abstraction, then the load time is comparable with picoweb. I'm glad you tried it and surprised that you didn't get the same results. Are you getting shorter load times with picoweb, or longer times with ws?
Edit, more testing...
I have an ESP8266 with an RGB LED on GPIO 5,12, and 13. I have prepared tests that respond to GET requests and set RGB values according to the GET query:
ws:
Code: Select all
import machine
import ws
r = machine.PWM(machine.Pin(13, machine.Pin.OUT), freq=500, duty=1023)
g = machine.PWM(machine.Pin(12, machine.Pin.OUT), freq=500, duty=1023)
b = machine.PWM(machine.Pin(5, machine.Pin.OUT), freq=500, duty=1023)
@ws.route('/rgb')
def rgb(query):
query = query.split(b',')
r.duty(int(query[0]))
g.duty(int(query[1]))
b.duty(int(query[2]))
ws.serve()
picoweb:
Code: Select all
import machine
import picoweb
r = machine.PWM(machine.Pin(13, machine.Pin.OUT), freq=500, duty=1023)
g = machine.PWM(machine.Pin(12, machine.Pin.OUT), freq=500, duty=1023)
b = machine.PWM(machine.Pin(5, machine.Pin.OUT), freq=500, duty=1023)
app = picoweb.WebApp(__name__)
@app.route("/rgb")
def index(req, resp):
query = req.qs.split(',')
r.duty(int(query[0]))
g.duty(int(query[1]))
b.duty(int(query[2]))
yield from resp.awrite("HTTP/1.0 200 OK\r\n\r\n")
app.run(host="0.0.0.0",port=80,debug=False)
Here's a shell command that cycles RGB every 200ms, and times each request:
Code: Select all
for ((n=0;n<10;n++)); do sh -c '
time -f "%e" wget -O/dev/zero -q http://10.0.0.191/rgb?1023,0,0;
sleep 0.2;
time -f "%e" wget -O/dev/zero -q http://10.0.0.191/rgb?0,1023,0;
sleep 0.2;
time -f "%e" wget -O/dev/zero -q http://10.0.0.191/rgb?0,0,1023;
sleep 0.2
'; done
ws
total reqest time for 30 requests: 0.69s
free memory after serving requests and collecting garbage: 24624
picoweb
total request time for 30 requests: 2.49s
free memory after serving requests and collecting garbage: 20448
ws is a barebones prototype and picoweb is a proper framework, so it's not a fair comparison. Adding a few features and more error handling is likely to slow ws down a bit, but this is not a small difference. Even without frozen bytecode, ws is running faster and with less memory than picoweb. I'm going to continue working on it, and I am going to prove that it is possible to use MicroPython without uasyncio for non-trivial asynchronous applications.