Skip to content

Conversation

@tmeinlschmidt
Copy link

The issue with 'abc/%/def' % string - this is pretty costly. Did a test on my M1 and this approach is 2.5x slower than that new one. With tens of repeated processing per second, this could significantly improve processing.

test is pretty simple

import timeit

def current():
    for dt in ('Grid', 'Genset'):
        for ph in ('L1', 'L2', 'L3'):
            '/Ac/PvOn%s/%s/Power' % (dt, ph)
            '/Ac/PvOn%s/%s/Current' % (dt, ph)
            '/Ac/%s/%s/Power' % (dt, ph)
            '/Ac/%s/%s/Current' % (dt, ph)

PATHS = {}
for dt in ('Grid', 'Genset'):
    for ph in ('L1', 'L2', 'L3'):
        PATHS[(dt, ph, 'pvp')] = '/Ac/PvOn%s/%s/Power' % (dt, ph)
        PATHS[(dt, ph, 'pvc')] = '/Ac/PvOn%s/%s/Current' % (dt, ph)
        PATHS[(dt, ph, 'p')] = '/Ac/%s/%s/Power' % (dt, ph)
        PATHS[(dt, ph, 'c')] = '/Ac/%s/%s/Current' % (dt, ph)

def precomputed():
    for dt in ('Grid', 'Genset'):
        for ph in ('L1', 'L2', 'L3'):
            PATHS[(dt, ph, 'pvp')]
            PATHS[(dt, ph, 'pvc')]
            PATHS[(dt, ph, 'p')]
            PATHS[(dt, ph, 'c')]

print('current:     ', timeit.timeit(current, number=100000))
print('precomputed: ', timeit.timeit(precomputed, number=100000))

For few compued values (like active_input+1, phase) it was kept as it is.

results (mac m1)

current:      0.30169125
precomputed:  0.12832187499999997

The issue with `'abc/%/def' % string` - this is pretty costly. Did a test
on my M1 and this approach is 2.5x slower than that new one. With tens
of repeated processing per second, this could significantly improve
processing.

test is pretty simple
````
import timeit

def current():
    for dt in ('Grid', 'Genset'):
        for ph in ('L1', 'L2', 'L3'):
            '/Ac/PvOn%s/%s/Power' % (dt, ph)
            '/Ac/PvOn%s/%s/Current' % (dt, ph)
            '/Ac/%s/%s/Power' % (dt, ph)
            '/Ac/%s/%s/Current' % (dt, ph)

PATHS = {}
for dt in ('Grid', 'Genset'):
    for ph in ('L1', 'L2', 'L3'):
        PATHS[(dt, ph, 'pvp')] = '/Ac/PvOn%s/%s/Power' % (dt, ph)
        PATHS[(dt, ph, 'pvc')] = '/Ac/PvOn%s/%s/Current' % (dt, ph)
        PATHS[(dt, ph, 'p')] = '/Ac/%s/%s/Power' % (dt, ph)
        PATHS[(dt, ph, 'c')] = '/Ac/%s/%s/Current' % (dt, ph)

def precomputed():
    for dt in ('Grid', 'Genset'):
        for ph in ('L1', 'L2', 'L3'):
            PATHS[(dt, ph, 'pvp')]
            PATHS[(dt, ph, 'pvc')]
            PATHS[(dt, ph, 'p')]
            PATHS[(dt, ph, 'c')]

print('current:     ', timeit.timeit(current, number=100000))
print('precomputed: ', timeit.timeit(precomputed, number=100000))
````
For few compued values (like `active_input+1, phase`) it was kept as it
is.

results (mac m1)
````
current:      0.30169125
precomputed:  0.12832187499999997
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant