Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String vs GString Performance

Tags:

groovy

Do we have hard performance data that demonstrates an advantage of single quotes over double-quotes? Most people will be more comfortable with double quotes.

I know GString can be used when we are evaluating the expression, and perform lazy evaluation

like image 462
anish Avatar asked Mar 19 '12 18:03

anish


1 Answers

Here's a link to some tests done back in '09:

http://pstehlik.com/2009/01/the-speed-difference-between-the-different-types-of-strings-in-groovy-and-grails/

The results did seem to vary a lot depending on whether you were using a String or GString, what you were doing with that object, and whether you were running on the console or on Jetty.

But being almost 3 years ago, much may have changed. The test script is still available at the bottom of the page, so you could try running that in your current Groovy version to see what the results are like now. You can also see his nabble post which may give some more information.

Personally, I use single-quote Strings more often than not, and just use double-quote GString when I need to use variable substitution. Never have tested the performance differences though.

like image 111
Kaleb Brasee Avatar answered Nov 19 '22 19:11

Kaleb Brasee