Skip to content

Tag: performance

Java Quick Sort Performance

I was doing sorting array problems and found one of the quick sorting solution extremely fast, and the only difference is the two lines of code in function 1Partition. Wondering why the following two lines of code in 1Partition can greatly improve the performance: Here’s the full source code: } Answer I guess you are doing the question on a

Split by regex vs multiple one char splits performance

I compared splitting string by regex and by multiple one char splits, using this benchmark and got these results Why splitting by regex is slower than splitting by multiple individual characters, even though they produce the same result? Note: I ran the code on JDK 14.0.2 I used JMH 1.28 Answer String.split implementation has the optimized fast path for splitting

Function chaining by returning parameter in Java

Seen regularly in the code and quite often used myself mostly to save myself a few lines. so that you can daisy chain the otherwise purely imperative methods in one-liners like as opposed to the classical way There is of course some potential for abuse if you go over board with the daisy chaining like return a(b(c(d(),e(),f(g())), h(i()),j()));, but let’s

Using StringBuilder to write XML vs XML library

I already understand from reading different threads that generating your own XML string using a StringBuilder is looked down upon, but the reason usually comes down to escaping characters. I’d like to know if anyone is experienced with XML libraries and writing XML using StringBuilders and know if there is a big difference in performance to writing an XML which