Core Java

Benchmark for new string methods of Java 11

While I was checking what’s new in Java 11, I saw that there are several new methods for String class. So I wanted to do a microbenchmark with old way of doing things and by using new methods. These new methods are;

boolean isBlank()

String strip()

Stream lines()

isBlank() is tested agains trim().isEmpty(), strip() is tested agains trim() and lines() is tested agains split().

Here are the results:

BenchmarkScore
lines3252919
split2486539
strip18280130
trim18222362
isBlank25126454
trim + isEmpty19854156

Scores are based on operations per second so the more the better.

As you can see lines() is much faster than split().

strip() and trim() performed quite similar.

isBlank() outperformed trim() + empty().

You can check the benchmark code here.

Published on Java Code Geeks with permission by Sezin Karli, partner at our JCG program. See the original article here: benchmark for new string methods of java 11

Opinions expressed by Java Code Geeks contributors are their own.

Sezin Karli

Mathematics Engineer & Computer Scientist with a passion for software development. Avid learner for new technologies. Currently working as Senior Software Engineer at Sahibinden.com.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
St1mpy
St1mpy
4 years ago

Wow what aa useless benchmark

Back to top button