Where the M1 really blows any other CPU away is single-threaded performance; multi-threaded performance is just normal. So it's not surprising that it's not faster than your 10-core iMac when compiling (which I assume is using 100% of every core).
In fact, given that the M1 is an 8-core CPU and your iMac has a 10-core CPU, the fact that they take 5 and 4 minutes respectively to compile seems to indicate that they're fairly similar in multi-threaded performance (and the iMac wins only because it has more cores).
In fact, given that the M1 is an 8-core CPU and your iMac has a 10-core CPU, the fact that they take 5 and 4 minutes respectively to compile seems to indicate that they're fairly similar in multi-threaded performance (and the iMac wins only because it has more cores).