python re模块安装_关于 Python re 模块和 google re2 模块

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:10   2416   0

测试代码:

from datetime import date

import tornado.escape

import tornado.ioloop

import tornado.web

class VersionHandler(tornado.web.RequestHandler):

def get(self):

response = { 'version': '3.5.1',

'last_build': date.today().isoformat() }

self.write(response)

class GetGameByIdHandler(tornado.web.RequestHandler):

def get(self, id):

response = { 'id': int(id),

'name': 'Crazy Game',

'release_date': date.today().isoformat() }

self.write(response)

application = tornado.web.Application([

(r"/getgamebyid/([0-9]+)", GetGameByIdHandler),

(r"/version", VersionHandler)

])

if name == "main":

application.listen(8888)

tornado.ioloop.IOLoop.instance().start()

python-re:

[[email protected] ~]$ webbench -c 1000 -t 60 -2 --get http://192.168.1.108:8888/getgamebyid/1

Webbench - Simple Web Benchmark 1.5

Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.1.108:8888/getgamebyid/1 (using HTTP/1.1)

1000 clients, running 60 sec.

Speed=80840 pages/min, 349074 bytes/sec.

Requests: 80247 susceed, 593 failed.

python-re2

Benchmarking: GET http://192.168.1.108:8888/getgamebyid/1 (using HTTP/1.1)

1000 clients, running 60 sec.

Speed=81921 pages/min, 0 bytes/sec.

Requests: 81430 susceed, 491 failed.

看起来能得得到小幅度的性能提升,但是 RE2 没有 groupindex 这个对象,会报错,估计得分析一下 pythgon-re2 的源码源码:

File "/usr/lib64/python2.7/site-packages/tornado/web.py", line 1994, in _find_handler

if spec.regex.groupindex:

AttributeError: 're2.Pattern' object has no attribute 'groupindex'

继续挖坑

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP