I wanted to answer a simple question:
When can an O(n) algorithm be a better choice than O(1) in a real system?
Not in a textbook example, but in something closer to a production payment system.
That question turned into an experiment involving three AI models, Java 21, JMH, several implementations of the same operation, and some unexpected results.
The most interesting part wasn't which algorithm won.
It was discovering that an AI model can write a benchmark, execute it, explain the results convincingly, and still make a mistake that compromises the experiment.
Here's what happened.
The problem: a payment authorization hot path
Imagine a fintech processing around 100,000 card authorizations per second , distributed across multiple service instances.
During authorization, the system needs to determine whether the merchant's MCC (Merchant Category Code) is blocked for the card's financial product.
MCCs identify merchant categories, such as restaurants, supermarkets, or gambling establishments.
Our…