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;
isBlank() is tested agains trim().isEmpty(), strip() is tested agains trim() and lines() is tested agains split().
Here are the results:
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.
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:
Benchmark | Score |
---|---|
lines | 3252919 |
split | 2486539 |
strip | 18280130 |
trim | 18222362 |
isBlank | 25126454 |
trim + isEmpty | 19854156 |
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.
No comments:
Post a Comment