对象的快速正则表达式
pyrefo的Python项目详细描述
###pyrefo:object
的快速regex这个项目基于[ref](https://github.com/machinalis/refo)和论文[正则表达式匹配:虚拟机方法](https://swtch.com/~rsc/regexp/regexp2.html)。它使用cffi用c扩展python以加速处理性能。
本项目完成了以下工作:
1。与refo api完全兼容,支持所有模式和match、search、finditer方法;
2。修复本文中的c源代码错误;
3。使用cffi用c;
4扩展python。添加支持部分匹配的新功能;
5。添加新的“短语”模式,可以实现“a b”匹配“a”、“b”、“c”列表;
='为什么在本店买东西?因为物流迅速+品质保证。为什么我购买的每件商品评价都一样呢?因为我买的东西太多了,积累了很多未评价的订单,所以我统一用这段话作为评价内容。如果我用了这段话作为评价,那就说明这款产品非常赞,非常好!'
tokens = 从pyrefo导入搜索,group,star,star,any,literal
%timeit search,any,literal
%timeit search(group(literal('29289;流‘’)+star(any())+literal('36805;‘’,'a’),'a’),'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’/>``外壳
95.9μs±472 ns/圈(7次运行的平均值±标准偏差,每人10000个循环)
``````
-refo
``python
import-refo
%timeit-refo.search(refo.group(refo.group(refo.literal(refo.literal('29289;流```
``shell
`````````````shell
>1.03 ms/>``````````````
``````````````````````````````
>1.03 ms/>```。共7次跑步,每人1000个循环)
````
-re
``python
import re
%timeit re.search('(物流.*度`,文本)
`````
````` shell
989 ns±4.69 ns/循环(7次运行的平均值±标准偏差,每人1000000个循环)
`````
``````
```````````````````````````````````````````pypy
-pyrefo
`` python
来自pyrefo import search,group,star,any,literal
%timeit search(group(literal('29289;流')+star(any())+literal('36805;'),'a'),tokens)
````
```` shell
53.4微秒±28微秒/循环(平均值±标准偏差,共7次运行,每1000个循环一次
`````
-refo
``python
import-refo
%timeit-refo.search(refo.group(refo.group(refo.literal('29289;流')+refo.star(refo.any())+refo.literal('36805;‘a’),'a’)、token)
`````````shell
>````````````````````
>>`````````````````````````7次跑步中,每个1000个循环)
```
-re
```外壳
import re
%timeit re.search('(物流.*接件)
`````
``外壳
347 ns±3.26 ns/循环(7次运行的平均值±标准偏差,每个循环1000000个)
```
的快速regex这个项目基于[ref](https://github.com/machinalis/refo)和论文[正则表达式匹配:虚拟机方法](https://swtch.com/~rsc/regexp/regexp2.html)。它使用cffi用c扩展python以加速处理性能。
本项目完成了以下工作:
1。与refo api完全兼容,支持所有模式和match、search、finditer方法;
2。修复本文中的c源代码错误;
3。使用cffi用c;
4扩展python。添加支持部分匹配的新功能;
5。添加新的“短语”模式,可以实现“a b”匹配“a”、“b”、“c”列表;
='为什么在本店买东西?因为物流迅速+品质保证。为什么我购买的每件商品评价都一样呢?因为我买的东西太多了,积累了很多未评价的订单,所以我统一用这段话作为评价内容。如果我用了这段话作为评价,那就说明这款产品非常赞,非常好!'
tokens = 从pyrefo导入搜索,group,star,star,any,literal
%timeit search,any,literal
%timeit search(group(literal('29289;流‘’)+star(any())+literal('36805;‘’,'a’),'a’),'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’,'a’/>``外壳
95.9μs±472 ns/圈(7次运行的平均值±标准偏差,每人10000个循环)
``````
-refo
``python
import-refo
%timeit-refo.search(refo.group(refo.group(refo.literal(refo.literal('29289;流```
``shell
`````````````shell
>1.03 ms/>``````````````
``````````````````````````````
>1.03 ms/>```。共7次跑步,每人1000个循环)
````
-re
``python
import re
%timeit re.search('(物流.*度`,文本)
`````
````` shell
989 ns±4.69 ns/循环(7次运行的平均值±标准偏差,每人1000000个循环)
`````
``````
```````````````````````````````````````````pypy
-pyrefo
`` python
来自pyrefo import search,group,star,any,literal
%timeit search(group(literal('29289;流')+star(any())+literal('36805;'),'a'),tokens)
````
```` shell
53.4微秒±28微秒/循环(平均值±标准偏差,共7次运行,每1000个循环一次
`````
-refo
``python
import-refo
%timeit-refo.search(refo.group(refo.group(refo.literal('29289;流')+refo.star(refo.any())+refo.literal('36805;‘a’),'a’)、token)
`````````shell
>````````````````````
>>`````````````````````````7次跑步中,每个1000个循环)
```
-re
```外壳
import re
%timeit re.search('(物流.*接件)
`````
``外壳
347 ns±3.26 ns/循环(7次运行的平均值±标准偏差,每个循环1000000个)
```