---
title: "Optimizing Magma Code"
canonical: "https://docs.magma-maths.org/v2.30-1/FiniteGroups/FiniteSolubleGroups/optimization.html"
source: "https://docs.magma-maths.org/v2.30-1/FiniteGroups/FiniteSolubleGroups/optimization.md"
part: "Finite Groups"
chapter: "Finite Soluble Groups"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Finite Groups", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/index-finite-groups.md"}
  - {"title": "Finite Soluble Groups", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/FiniteSolubleGroups/index-finite-soluble-groups.md"}
prev: {"title": "More About Presentations", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/FiniteSolubleGroups/more-presentations.md"}
next: {"title": "$p$-Groups of Tame Genus", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/FiniteSolubleGroups/tame.md"}
examples:
  - "ex-952208"
---

# Optimizing Magma Code

## PowerGroup

If the user is working with enumerated sets of pc-groups that are all subgroups of a common over-group $G$, then the following optimization is strongly recommended. Define the set to have the universe `PowerGroup(G)`. For any subgroup $H$ of $G$, we can find a canonical form for the generators of $H$. This allows us to have a very good hashing function for the subgroups.

<a id="example-ex-952208"></a>
### `Example: Optimising with a Power Group (ex-952208)`

The following example illustrates the optimization.

```magma
> G := ExtraSpecialGroup( GrpPC, 3, 3 );
> P := PowerGroup(G);
> time s1 := {  P | sub< G | Random(G), Random(G) > : x in { 1..500}  };
Time: 1.140
> time s2 := { Parent(G) | sub< G | Random(G), Random(G) > : x in { 1..500}  };
Time: 9.769
```
