[apparmor] [patch] - performance again... small changes
Peter Maloney
peter.maloney at brockmann-consult.de
Thu Nov 27 08:06:45 UTC 2014
On 11/27/2014 12:36 AM, Seth Arnold wrote:
> On Wed, Nov 26, 2014 at 10:57:13PM +0100, Peter Maloney wrote:diff -ur apparmor.orig/aamode.py apparmor.p1/aamode.py
> --- apparmor.orig/aamode.py 2014-07-14 20:56:26.000000000 +0200
> +++ apparmor.p1/aamode.py 2014-11-09 22:15:01.875415033 +0100
>
> ...
>
> -MODE_MAP_RE = re.compile('(r|w|l|m|k|a|x|i|u|p|c|n|I|U|P|C|N)')
> +MODE_MAP_LIST = ["r", "w", "l", "m", "k", "a", "x", "i", "u", "p", "c", "n", "I", "U", "P", "C", "N"]
>
> ...
>
> + for mode_char in string:
> + if mode_char not in MODE_MAP_LIST:
> break
> ...
> The mode.split("::") speedup makes a ton of sense. I'm less convinced of
> the MOD_MAP_LIST lookup, that's a long list to iterate through. If you're
> up for more testing, I'm curious about the performance difference of only
> the :: splitting, only the MODE_MAP_LIST, and perhaps using MOD_MAP_SET =
> { 'r', 'w'. 'l', ...} as well.
>
> For just the split_log_mode() change,
> Acked-by: Seth Arnold <seth.arnold at canonical.com>
>
>
Yes I agree that a dict would likely be faster than a list, even a small
list like that one. (attached new patch)
from timeit import timeit
MODE_MAP_LIST = ["r", "w", "l", "m", "k", "a", "x", "i", "u", "p", "c",
"n", "I", "U", "P", "C", "N"]
MODE_MAP_SET = {"r", "w", "l", "m", "k", "a", "x", "i", "u", "p", "c",
"n", "I", "U", "P", "C", "N"}
def testlist():
for i in MODE_MAP_LIST:
i in MODE_MAP_LIST
def testset():
for i in MODE_MAP_LIST:
i in MODE_MAP_SET
timeit(testlist, number=10000)
timeit(testset, number=10000)
>>> timeit(testlist, number=10000)
0.0441557650001414
>>> timeit(testset, number=10000)
0.016543965999971988
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p1b-regexthing.patch
Type: text/x-patch
Size: 1450 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20141127/d8273d33/attachment-0001.bin>
More information about the AppArmor
mailing list