-
Type: Improvement
-
Status: Resolved
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: 2.1.707
-
Component/s: Framework
-
Epic Link:
-
Tags:
-
Team:DRIVE
-
Sprint:nxDrive 11.1.23
-
Story Points:0
The current implementation is using re.sub() to replace a set of characters in filenames.
After a small benchmark, and given the huge number of filenames Drive is is dealing with, this micro optimization may be interesting.
from timeit import repeat setup1 = r""" import re pattern = re.compile(r'([aetuo])') value = "azertyuiop" """ setup2 = """ repmap = {ord(c): "-" for c in "aetuo"} value = "azertyuiop" """ print(repeat("re.sub(pattern, '-', value)", setup1, number=100000)[1]) print(repeat("value.translate(repmap)", setup2, number=100000)[1])
The script first test the current implementation using re.sub().
The second is using a potential better implementation, using str.translate().
Results:
re.sub() : 0.23668296402320266
str.translate(): 0.05809920001775026
This is a significative improvement on the performance level.
- is related to
-
NXP-11359 Documents with forbidden filename chars such as * / or \ trigger 404 error and prevent synchronization
- Resolved