# Asking multiple AI to optimise the same code

DevFeed: [Asking multiple AI to optimise the same code](<https://devfeed.tech/articles/asking-multiple-ai-to-optimise-the-same-code-30757.md>)

Original publisher: [Read original article](<http://blog.vanillajava.blog/2025/07/asking-multiple-ai-to-optimise-same-code.html>)

Author: Peter Lawrey (noreply@blogger.com)

Published: 2025-07-16T21:11:00Z

Content type: opinion

Language: en

Sources: [Vanilla Java](<https://devfeed.tech/sources/vanilla-java.md>)

Topics: [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [Code](<https://devfeed.tech/topics/code.md>), [long-context](<https://devfeed.tech/topics/long-context.md>), [Claude](<https://devfeed.tech/topics/claude.md>), [GitHub Copilot](<https://devfeed.tech/topics/github-copilot.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [claude](<https://devfeed.tech/tags/claude.md>), [code](<https://devfeed.tech/tags/code.md>), [context-window](<https://devfeed.tech/tags/context-window.md>), [copilot](<https://devfeed.tech/tags/copilot.md>), [exercise](<https://devfeed.tech/tags/exercise.md>), [openai](<https://devfeed.tech/tags/openai.md>), [opinion](<https://devfeed.tech/tags/opinion.md>), [performance](<https://devfeed.tech/tags/performance.md>)

## AI overview

The article compares how multiple AI systems optimize the same Java code. It reports that the systems produce different results, with some solutions introducing bugs or taking longer, and recommends using multiple opinions rather than treating one model as consistently best.

## Source excerpt

As different AIs are implemented differently, they don't all provide the same answer, nor do they consistently outperform one another. The best approach is to use multiple AI and pick the one you like best. My goal here is not to declare a winner based on one example, but instead to show the variety of answers you can get with different AI. I asked each AI to Suggest how to implement this more optimally private static String formatOffset(int millis) { String sign = millis < 0 ? "-" : "+"; int saveSecs = Math.abs(millis) / 1000; int hours = saveSecs / 3600; int mins = ((saveSecs / 60) % 60); int secs = (saveSecs % 60); if (secs == 0) { if (mins == 0) { return sign + twoDigitString(hours); } return sign + twoDigitString(hours) + twoDigitString(mins); } return sign + twoDigitString(hours) + twoDigitString(mins) + twoDigitString(secs); } private static String twoDigitString(int value) { return Integer.toString(value + 100).substring(1); } Gemini 2.5 pro While Gemini is often my first go-to AI when I have a large code base, it's not the smartest. It does have a large context window, which means I can dump a large context into it without much thought on my part. However, if you have less than about 6,000 lines of context, you might find that o3-pro, o4-mini-high, or Claude 4 gives a better answer. In this case, it offered in about 10 seconds; private static String formatOffset(int millis) { long totalSeconds = Math.abs((long) millis / 1000); long hours = totalSeconds / 3600; long minutes = (totalSeconds % 3600) / 60; long seconds = totalSeconds % 60; StringBuilder sb = new StringBuilder(); sb.append(millis < 0 ? "-" : "+"); sb.append(String.format("%02d", hours)); if (minutes > 0 || seconds > 0) { sb.append(String.format(":%02d", minutes)); } if (seconds > 0) { sb.append(String.format(":%02d", seconds)); } return sb.toString(); } Not only is this approach slower, but it also fails to achieve the same result, which is even worse. The original format is +HHMMSS without a co