Faster alternative for 'Mass addition' component?

Hi I Have a lage list with Fals/True items.
I would like to count the number of True items.

Normally I use the Mass addition component but this is quite slow…

Any suggestions for an alternative?

Many thanks :slight_smile:

Cull Pattern + List Length seems to be 10x faster on this simple test.

1 Like

The overhead there is obviously converting integers to Boolean. Skipping that, Cull Pattern has the overhead internally. Python is only slightly faster than MA summing integers or Booleans. ‘List access’ and ‘No Type Hint’ on the Python ‘x’ input. If type hint is ‘bool’, it’s almost as slow as the others (4.9s). Advantage over MA is insignificant.

sum = 0
for k in range(len(x)):
    sum += x[k];
a = sum

ma_python

ma_python2

ma_python3

P.S. Oh, wait! Python has a 'sum()’ function that is faster, as long as Python ‘x’ input is ‘No Type Hint’. 139ms for integers, 204ms for Booleans.

a = sum(x)

1 Like