Today I decided to check the performance of different ways of converting an int variable to a String object in Java. 🧵👇
I searched on Stackoverflow:
📍Integer.toString(i)
📍"" +i
📍String.valueOf(i)
📍new StringBuilder().append(i).toString() - a bit strange way, but it was one of the suggestions😄
I have implemented 4 benchmarks using the JMH framework (see pictures).
The Pareto Principle suggests that in some cases, the majority of results come from a minority of inputs: 👇
📍80% of a certain piece of software can be written in 20% of the total allocated time (conversely, the hardest 20% of the code takes 80% of the time)
📍20% of the effort produces 80% of the result
📍20% of the work creates 80% of the revenue
📍20% of the bugs cause 80% of the crashes
📍20% of the features cause 80% of the usage
A management concept developed by Scott Adams (creator of the Dilbert comic strip), the Dilbert Principle is inspired by The Peter Principle.
Under the Dilbert Principle, employees who were never competent are promoted to management in order to limit the damage they can do. Adams first explained the principle in a 1995 Wall Street Journal article, and expanded upon it in his 1996 business book, The Dilbert Principle.
The more talented and effective IT engineers are the ones most likely to leave - to evaporate ... [those who tend to] remain behind [are] the 'residue' — the least talented and effective IT engineers. 🤓
--Bruce F. Webster
The "Dead Sea Effect" suggests that in any organisation, the skills/talent/efficacy of engineers is often inversely proportional to their time in the company.
Typically, highly skilled engineers find it easy to gain employment elsewhere and are the first to do so.
Engineers who have obsolete or weak skills will tend to remain with the company, as finding employment elsewhere is difficult.
I decided to compare the performance of different collection iteration options. In particular:
📍 for loop
📍enhanced for loop
📍for loop with an Iterator
📍stream
Details🧵👇
To test it, I have implemented 4 Benchmark methods, each iterating through list of positive integers and checking them for equality to -1. And at the end of the method, it returns 0 since non was found. In short: Just iterating through the entire collection.
Results:
✅for (Integer i : list) 781 ns/op
✅for (int i = 0; i < listSize; i++) 785 ns/op
✅while (iterator.hasNext()) 788 ns/op
❌list.stream() ns/op 3256 ns/op 4x slower 😱👀
⚠️Top 5 Trending Java GitHub repositories February 2023⚠️
(Android excluded)
🧵👇
1️⃣ OpenAI-Java - Java libraries for using OpenAI's GPT-3 api.
Includes:
api - request/response POJOs for the GPT-3 APIs
client - retrofit client for the GPT-3 endpoints
service - service class that creates and calls the client
2️⃣Karate - is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.
To show the difference in performance between primitive and wrapper objects I have created a benchmark which just creates an array of "int" and "Integer" and fills them with an index. Sizes of array: "10", "100", "1000", "10000"