Computing the length of a finite group Can someone suggest a GAP or MAGMA command (or code) to obtain the length $l(G)$ of a finite group $G$, i.e. the maximum length of a strictly descending chain of subgroups in $G$?
Thanks in advance.

Here is yet another version. It includes all of Jack's ideas, but it also uses a lazy way of adding up the lengths of the nonabelian composition factors. It performs much faster on example lie $A_5 \wr A_5$. I am sure it could be further improved!
subgroupLengthNew := function( grp )
  len := $$;
  if #grp eq 1 then return 0;
  elif IsSolvable( grp ) then return
      &+[ pn[2] : pn in FactoredOrder( grp ) ];
  elif IsSimple(grp) then return
      1 + Max( { len( max`subgroup ) : max in MaximalSubgroups( grp) } );
  else
    top := SolvableQuotient( grp );
    if #top gt 1 then bot := SolvableResidual( grp );
    else top, _, bot := RadicalQuotient( grp );
    end if;
    if #top gt 1 and #bot gt 1 then
      return &+[ len( part ) : part in [* top, bot *] ];
    else //add up over composition factors 
      tot := 0;
      cs := CompositionSeries( grp ); //goes from top down
      for i in [1..#cs-1] do
        ind := Index( cs[i], cs[i+1] );
        fac := Factorisation( ind );
        if IsPrime( ind ) then tot +:= 1;
        else
         //nonabelian simple factor - get perm rep on Sylow normaliser
          if i eq #cs-1 then I :=  cs[i];
          else
            _,pos := Max( [ f[1]^f[2] : f in fac ] );
            S := sub< cs[i] | cs[i+1], Sylow(cs[i], fac[pos][1]) >;
            I := CosetImage( cs[i], Normalizer( cs[i], S ) );
          end if;
          tot +:= len(I);
        end if;
      end for;
      return tot;
    end if;
  end if;
end function;

