<p>I'm trying to teach the basics of benchmarking and optimising .NET code. This is to other established engineers, not university students.</p>
<p>I want to start off with a badly optimised algorithm and then we can interactively optimise during the talk.</p>
<p>Has anyone got good example algorithms that have a reasonable looking naive implementation but also reasonably obvious paths to optimisation that I could use for this?</p>
<p>My initial thought is a prime finder, but I was hoping for something a little more interesting and that doesn't rely on my audience knowing about some of the less obvious mathematical properties optimising a prime finder requires.</p>

CC BY-SA 4.0
2023-07-04T13:03:45.873Z
Are you interested in theoretical algorithmical optimizations (e.g. optimizations which have an impact on the Big-O) or practical constant factor optimizations (say, using a bit set instead of wastefully using an array or the like, or improving cache locality, reducing branching etc), or both?
Luatic
CC BY-SA 4.0
2023-07-04T16:50:07.480Z
@Luatic - Both, but stuff that there's a good chance of an engineer thinking of in a minute or two, not stuff that needs huge logical leaps.
ScottishTapWater
CC BY-SA 4.0
2023-07-11T15:07:21.680Z
A good optimization lesson will focus on how there is never just one thing to optimize. Sometimes space is sacrificed for time.  Sometimes time is sacrificed for space. Often readability is sacrificed for no good reason.
candied_orange
<exercises>
Good example for a live optimisation exercise
# Good example for a live optimisation exercise

(Asked by: username_0 on 2023-06-29)

I'm trying to teach the basics of benchmarking and optimising .NET code. This is to other established engineers, not university students.

I want to start off with a badly optimised algorithm and then we can interactively optimise during the talk.

Has anyone got good example algorithms that have a reasonable looking naive implementation but also reasonably obvious paths to optimisation that I could use for this?

My initial thought is a prime finder, but I was hoping for something a little more interesting and that doesn't rely on my audience knowing about some of the less obvious mathematical properties optimising a prime finder requires.

**Tags:** exercises

> **Comments:**
> **username_1**: Are you interested in theoretical algorithmical optimizations (e.g. optimizations which have an impact on the Big-O) or practical constant factor optimizations (say, using a bit set instead of wastefully using an array or the like, or improving cache locality, reducing branching etc), or both?  
> **username_0**: @username_1 - Both, but stuff that there's a good chance of an engineer thinking of in a minute or two, not stuff that needs huge logical leaps.  
> **username_2**: A good optimization lesson will focus on how there is never just one thing to optimize. Sometimes space is sacrificed for time.  Sometimes time is sacrificed for space. Often readability is sacrificed for no good reason.  

---

## 0 answers

