This AI Agent Writes Its Own Story
A software development experience building an autonomous AI agent using AI coding and brainstorming assistants - the benefits, challenges, and insights gained
This experiment is a bit more complex than the previous two experiments in this series. It consists of looping through 2 different lists and comparing the objects inside them using different equality methods to see which of them work, which don’t, which ones are slow and which are fast.
The basic pseudo-code would be:
for j in size(lists) {
compare listA[j] to listB[j]
}
The source on this test is quite complex, so I couldn’t simply run it on IDE One like before. But hey, I’m still sharing the sources, so you can run this locally.
I am going to be testing 2 different scenarios - one uses class inheritance and the other one doesn’t.
In the first example, our base class extends java.lang.Object
(POJO) and implements the Comparable
interface – so nothing extraordinary and nothing fancy. In a dramatic twist, the other class extends that first class.
I decided to call them LevelOneClass
and LevelTwoClass
.
LevelOneClass
is basically bundling 2 Strings, while LevelTwoClass
is an extended version of the previous class, adding one more String to the bundle.
Now to the interesting part, the comparison. I came up with 5 comparison methods, some of them reliable and some serving as the baseline:
equals()
on both objectshashCode()
on both objectssuper.equals()
to checksuper.hashCode()
to checkequals()
method on each field. If a single field fails the comparison, the whole comparison returns false
. This one should be the most precise version, as it deeply inspects the whole object’s structure and its data (albeit probably the worst performer)On to the fun part – results. The test was quite extensive and long, so I can’t share the full output directly in the post, but I can link to the results:
It seems that the good-old manual comparison by equals()
comes in first, even faster than the hashCode()
variant. Of course, super.equals()
is way faster, but it’s incorrect and serves only as the baseline.
As expected, our reflective comparison is the slowest.