Viktar Patotski Profile picture
Feb 26 4 tweets 2 min read
#Java performance comparison.

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).

Results 👇
✅Integer.toString(i) - 43.424 29.721 ns/op
✅"" +i - 27.870 ns/op
✅String.valueOf(i) - 28.371 ns/op
❌new StringBuilder().append(i).toString() - ns/op

Just don't use StringBuilder approach. Other approaches are for your taste. but I personally prefer: String.valurOf(i).
That's a wrap!

If you enjoy my Java learning content:

1. Follow me @xpvit for more Java, Cloud, and Linux knowledge.
2. RT the tweet below to share this thread with your audience

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Viktar Patotski

Viktar Patotski Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @xpvit

Feb 27
The Pareto Principle (The 80/20 Rule)

Most things in life are not distributed evenly.

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
Read 5 tweets
Feb 26
The Dilbert Principle

Companies tend to systematically promote incompetent employees to management to get them out of the workflow.

-- Scott Adams

en.wikipedia.org/wiki/Dilbert_p…
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.
Read 4 tweets
Feb 25
The Dead Sea Effect

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.
Read 5 tweets
Feb 18
⚠️#Java performance comparison⚠️

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 😱👀
Read 6 tweets
Feb 17
⚠️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

by @TheoKanning
github.com/TheoKanning/op…
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.

by @getkarate

github.com/karatelabs/kar…
Read 7 tweets
Feb 11
⚠️#Java performance tip⚠️
Use primitive types instead of wrappers.

Java primitive types:
📍byte
📍short
📍int
📍long
📍float
📍double
📍char
📍boolean

More details and explanation in 🧵👇
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"

Results: 👇
Array of size 10:
❌ arrayOfWrappers 26.131 ns/op - 2.7x slower
✅ arrayOfPrimitives 9.462 ns/op
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(