web.py bottle flask都是使用easy_install安装的,web.py0.34,flask0.6,bottle0.82
打印的页面都是简单的helloworld
—————————————————web.py——————————————————
import web
urls = (
'/', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello World!'
if __name__ == "__main__":
app.run()
—————————————————flask————————————————————
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
————————————————bottle————————————————————
from bottle import route, run
@route('/')
def index():
return 'Hello World!'
run(host='localhost', port=8000)
————————————————————————————————————
其中bottle和flask的在firefox3.68上显示效果完全相同,但是web.py不知是什么原因却自动输出了等宽字体(这个只是个人的疑惑,对效率应该没有影响)
介绍一下测试环境 cpu是i5 430m的,然后操作系统是ubuntu10.04 amd64 desktop的,python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
kernel 2.6.32-24-generic,大概就是这么多了
测试工具是apachebench2.3,参数是每个程序测试20次,很简单的测试
直接看输出吧
————————————————————首先是web.py——————————————————
billma@billma-laptop:~$ ab -n 20 http://0.0.0.0:8080/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 0.0.0.0 (be patient).....done
Server Software: CherryPy/3.1.2
Server Hostname: 0.0.0.0
Server Port: 8080
Document Path: /
Document Length: 12 bytes
Concurrency Level: 1
Time taken for tests: 0.056 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 2080 bytes
HTML transferred: 240 bytes
Requests per second: 357.34 [#/sec] (mean)
Time per request: 2.798 [ms] (mean)
Time per request: 2.798 [ms] (mean, across all concurrent requests)
Transfer rate: 36.29 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 2 3 0.9 2 5
Waiting: 2 3 0.9 2 5
Total: 2 3 0.9 2 5
WARNING: The median and mean for the processing time are not within a normal deviation
These results are probably not that reliable.
WARNING: The median and mean for the waiting time are not within a normal deviation
These results are probably not that reliable.
WARNING: The median and mean for the total time are not within a normal deviation
These results are probably not that reliable.
Percentage of the requests served within a certain time (ms)
50% 2
66% 3
75% 3
80% 3
90% 5
95% 5
98% 5
99% 5
100% 5 (longest request)
————————————————————再来flask————————————
billma@billma-laptop:~$ ab -n 20 http://127.0.0.1:5000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: Werkzeug/0.6.2
Server Hostname: 127.0.0.1
Server Port: 5000
Document Path: /
Document Length: 12 bytes
Concurrency Level: 1
Time taken for tests: 0.024 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 3300 bytes
HTML transferred: 240 bytes
Requests per second: 830.77 [#/sec] (mean)
Time per request: 1.204 [ms] (mean)
Time per request: 1.204 [ms] (mean, across all concurrent requests)
Transfer rate: 133.86 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1 1 0.4 1 2
Waiting: 0 1 0.4 1 2
Total: 1 1 0.5 1 2
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 2
95% 2
98% 2
99% 2
100% 2 (longest request)
————————————————最后是bottle的——————————————————
billma@billma-laptop:~$ ab -n 20 http://localhost:8000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: WSGIServer/0.1
Server Hostname: localhost
Server Port: 8000
Document Path: /
Document Length: 12 bytes
Concurrency Level: 1
Time taken for tests: 0.013 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 3300 bytes
HTML transferred: 240 bytes
Requests per second: 1503.31 [#/sec] (mean)
Time per request: 0.665 [ms] (mean)
Time per request: 0.665 [ms] (mean, across all concurrent requests)
Transfer rate: 242.23 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 0 1 0.2 0 1
Waiting: 0 0 0.2 0 0
Total: 0 1 0.3 1 1
ERROR: The median and mean for the processing time are more than twice the standard
deviation apart. These results are NOT reliable.
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 1
95% 1
98% 1
99% 1
100% 1 (longest request)
就是这样了,可以看出,bottle已经把另外两个微框架拉的很远了,另外,我还用fapws3+bottle做了测试,结果是0.009s,这样成绩直接秒杀其他的框架了……
Aug 2