Skip to content

Commit

Permalink
Improve rendering of speed benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Quentel committed Jan 1, 2017
1 parent 29e4784 commit 8bce525
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cgi-bin/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cgi
import time

print('Content-type: text/html\n\n')
print('Content-type: text/html\n')

if os.environ['REMOTE_ADDR']!='127.0.0.1':
print('forbidden access')
Expand All @@ -14,4 +14,4 @@
src = fs['src'].value
t0 = time.perf_counter()
exec(src)
print('CPython: %6.2f ms' % ((time.perf_counter() - t0) * 1000.0))
print('%6.2f' % ((time.perf_counter() - t0) * 1000.0))
16 changes: 12 additions & 4 deletions www/speed/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ def err_msg():
doc["result"].html = "server didn't reply after %s seconds" %timeout

def on_complete(req):
print(req.text)
resp = req.text.strip()
print('CPython:', resp, 'ms')
result['CPython'] = resp

result = None

# run a script, in global namespace if in_globals is True
def run(in_globals=False):
global output
global result
doc["console"].value = ''
src = editor.getValue()
if storage is not None:
Expand All @@ -109,18 +114,21 @@ def run(in_globals=False):
traceback.print_exc(file=sys.stderr)
state = 0
output = doc["console"].value

brython_time = (time.perf_counter() - t0) * 1000.0

print('Brython: %6.2f ms' % ((time.perf_counter() - t0) * 1000.0))
print('Brython: %6.2f ms' % brython_time)
result = {'Brython': '%6.2f' %brython_time}

# run with CPython
req = ajax.ajax()
req.bind('complete',on_complete)
req.set_timeout(4,err_msg)
req.open('POST','/cgi-bin/speed.py',True)
req.open('POST', '/cgi-bin/speed.py', False)
req.set_header('content-type','application/x-www-form-urlencoded')
req.send({'src':src})

return state
return state, result

def show_js(ev):
src = editor.getValue()
Expand Down
29 changes: 26 additions & 3 deletions www/speed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
<!-- script type="text/javascript" src="../src/async.js"></script -->

<script type="text/python3">
from browser import document as doc
from browser import document as doc, window
from browser import timer
from browser.html import *
import time
import sys

import editor

Expand All @@ -60,6 +62,8 @@

__BRYTHON__.debug = int(doc['set_debug'].checked)

results = []

def test_next():
global script_num,failed
script_num += 1
Expand All @@ -69,20 +73,39 @@
src = open(option.value).read()
doc['files'].selectedIndex = script_num
editor.editor.setValue(src)
state = editor.run()
state, result = editor.run()
result['test'] = option.value
results.append(result)
if state == 0:
failed.append(option.text)
timer.set_timeout(test_next,500)
else:
doc['console'].value = ''
print('completed all tests in %.2f s' %(time.time()-t_start))
print('failed : %s' %failed)
w = window.open()

head = w.document.get(selector="head")
head[0] <= LINK(rel="stylesheet", href=__BRYTHON__.brython_path+"/doc/doc_brython.css")

body = w.document.body
table = TABLE(border=1)
table <= TR(TH('test')+TH('Brython'))
for result in results:
row = TR()
row <= TD(result['test'])
row <= TD(int(100*float(result['Brython'])/float(result['CPython'])),
align="right")
table <= row
body <= H1("Brython performance (base 100 = CPython)")
body <= table

def test_all(ev):
global script_num,failed,t_start
global script_num, failed, t_start, results
script_num = -1
t_start = time.time()
failed = []
results = []
test_next()

def set_debug(ev):
Expand Down

0 comments on commit 8bce525

Please sign in to comment.