Posts

Showing posts with the label Performance / Benchmark

String Concatenation vs StringBuilder Performance Benchmark

Image
This single Java class benchmark, shows impressively that the penalty for using StringBuilder instead of regular String concatenation can be around 5x ! Many static code analyzers like PMD / SonarQube deceptively claim the opposite. This assumption might be a vestige from the pre Java 5 era. Indeed some developers even concatenate compile time constants ( static final ) using StringBuilder. Although be warned , when it comes to using effectively non-final variables inside the concatenation, StringBuilder will drastically outperform the regular String concatenation by several orders of magnitude. Effectively non-final variables are references that are not fixed. On the other hand effectively final values do not necessarily need be prefixed with the " final " keyword but they could be , which differentiates them from effectively non-final variables, that cannot be prefixed with the " final " keyword without causing a compilation error. To state it clear ...

Go / Golang's RegExp / String Performance

Working with Go I've experienced some perceived slowness when  performing RegEx operations on strings. I've looked for benchmarks and  found  this one .   In some areas Go kann keep up with Java but when it comes to string operations ("regex-dna" benchmark), Go is even much slower than Ruby or Python. Is the status quo going to improve anytime soon? And why is Go so terribly slow when it comes to string/RegEx operations?   And here is the  explanation why... , and  this one, shows the explanation even graphically .

Perl / Python / Ruby / PHP RegEx implementation VS Go / Golang's implementation

Image
Introduction This is a tale of two approaches to regular expression matching. One of them is in widespread use in the standard interpreters for many languages, including Perl. The other is used only in a few places, notably most implementations of awk and grep. The two approaches have wildly different performance characteristics:     Time to match a?nan against an Let's use superscripts to denote string repetition, so that a?3a3 is shorthand for a?a?a?aaa. The two graphs plot the time required by each approach to match the regular expression a?nan against the string an. Notice that Perl requires over sixty seconds to match a 29-character string. The other approach, labeled Thompson NFA for reasons that will be explained later, requires twenty microseconds to match the string. That's not a typo. The Perl graph plots time in seconds, while the Thompson NFA graph plots time in microseconds: the Thompson NFA impleme...