努力提高以下的正則表達式:提高蟒蛇正則表達式的性能
urlpath=columns[4].strip()
urlpath=re.sub("(\?.*|\/[0-9a-f]{24})","",urlpath)
urlpath=re.sub("\/[0-9\/]*","/",urlpath)
urlpath=re.sub("\;.*","",urlpath)
urlpath=re.sub("\/",".",urlpath)
urlpath=re.sub("\.api","api",urlpath)
if urlpath in dlatency:
這種轉換這樣的URL:
/api/v4/path/apiCallTwo?host=wApp&trackId=1347158
到
api.v4.path.apiCallTwo
想嘗試和改進正則表達式的性能,每5分鐘該腳本大約運行50,000個文件,大約需要40秒時代運行。
謝謝
確定正則表達式是腳本中的瓶頸,而不是硬盤嗎? –
磁盤IO相當低。腳本逐行反向讀取日誌文件,直到達到5分鐘以上的行。 – coderwhiz
這是基於分析代碼還是直覺? – hexparrot