Finding When Premature Optimization Is Evil

This article is based on the Software Mistakes and Tradeoffs book by Tomasz Lelek and Jon Skeet.

There is an old computer science saying that Premature Optimization is the root of all evil. The saying has stuck around because it’s accurate for a lot of use cases. Without any input data about expected traffic and SLA, it’s hard to reason about your code and its required performance. Optimizing random paths in code in such a situation is like shooting in the dark. You will complicate your code for no good reason. 

What Is Microbenchmarking?

Introduction

Optimisation of code is an endless struggle. It is often even hard to produce meaningful metrics using jvm as it is an adaptive virtual machine. The article is

  • a brief introduction to microbenchmarking,
  • why microbenchmark,
  • when to consider it, and finally,
  • pitfalls to avoid

What Is a Microbenchmark

A microbenchmark is an attempt to measure the performance of a small unit of code. The tests are usually in the sub-millisecond range. The tests can help determine how the code is going to behave when released into production. These tests are guide to a better implementation.