{"id":9287,"date":"2017-06-29T03:40:58","date_gmt":"2017-06-29T03:40:58","guid":{"rendered":"http:\/\/abstracta.us\/?p=9287"},"modified":"2025-05-05T21:20:49","modified_gmt":"2025-05-05T21:20:49","slug":"apache-groovy-vs-beanshell-make-right-decision","status":"publish","type":"post","link":"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/","title":{"rendered":"Apache Groovy vs BeanShell: How to Make the Right Decision?"},"content":{"rendered":"<p><!-- Go to www.addthis.com\/dashboard to customize your tools --><script src=\"\/\/s7.addthis.com\/js\/300\/addthis_widget.js#pubid=ra-58d80a50fc4f926d\" type=\"text\/javascript\"><\/script><\/p>\n<h1><span style=\"font-weight: 400; color: #333333;\">See what makes Groovy, groovy.<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">When running load tests in Apache JMeter, in many cases it&#8217;s necessary to choose a <\/span><span style=\"font-weight: 400;\">post processor\/scripting language for certain tasks, such as handling SampleResult variables, assigning dynamic names to samplers or just adding some logic to scripts. We have several options to choose from, but in this post we will look at two in particular: <strong>BeanShell vs\u00a0Groovy<\/strong> and why we are partial to Groovy. But, instead of trying to convince you why we believe Groovy is the better choice, we\u2019ll present the facts and let them speak for themselves!<\/span><\/p>\n<p><a href=\"http:\/\/www.beanshell.org\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">BeanShell<\/span><\/a><span style=\"font-weight: 400;\"> is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.<\/span><\/p>\n<p><a href=\"http:\/\/www.groovy-lang.org\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Apache Groovy<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">on the other hand<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"> is a dynamic object-oriented programming language that can be used as a scripting language for the Java platform.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s take a deeper look at the main characteristics of each:<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"BeanShell\"><\/span><strong><span style=\"color: #00b674;\">BeanShell<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><span style=\"font-weight: 400;\">Supports <em>for loops<\/em> and<em> foreach loops<\/em><\/span><\/li>\n<li><span style=\"font-weight: 400;\">Syntax for array initialization is similar to java<\/span><\/li>\n<li><span style=\"font-weight: 400;\">BeanShell can\u2019t run a script written for Groovy as it is based on JDK1.4, so it has no generic features<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Execution environment is 1.4 or more but doesn&#8217;t support generics<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Doesn\u2019t support writing a method with variable arguments or calling a method with variable arguments<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Doesn\u2019t support assigning certain hexadecimal values to the primitive data types. For example, int i = 0x80018000 throws an exception from the BeanShell interpreter saying the size is big. A BigInteger is to be used in this case, which is, again, tedious as we have to do something like this: BigInteger i = new BigInteger(&#8220;0x80018000&#8221;);<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Apache_Groovy\"><\/span><strong><span style=\"color: #00b674;\">Apache Groovy<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><span style=\"font-weight: 400;\">Groovy engine can run a script written for BeanShell<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Supports generics and collections with generics. Also supports raw types e.g.&gt; ArrayList str = new ArrayList()<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Supports calling methods with variable arguments e.g. method(int&#8230;i)<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Supports primitive data types like int to assign 4 byte hexa-decimal values eg. int i = 0x80018000<\/span><\/li>\n<li><span style=\"font-weight: 400;\">The syntax for array initialization is a bit different from java e.g. In java, array is initialized as int[] array = {1,2,3}; In groovy, it&#8217;s is done as int[] array = [1,2,3]<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Supports <em>for loops<\/em> and <\/span><i><span style=\"font-weight: 400;\">foreach<\/span><\/i><span style=\"font-weight: 400;\"><em> loops<\/em> etc.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Development and support: The Groovy language is constantly being developed, maintained and supported<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Java compatibility: valid Java code in 99% of cases will be valid Groovy code<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Groovy scripts can be statically compiled providing near Java code performance<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Native support of regular expressions, XML, JSON<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Simplified work with files<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Perhaps one of the most important features that we have mentioned about Groovy is the fact that it\u2019s statically compiled, which means that we can obtain top-notch performance, similar to what we would achieve using Java.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To see the difference in performance, we can take a look at the following chart from this <\/span><a href=\"http:\/\/www.testautomationguru.com\/jmeter-post-processors-script-language-comparison\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">helpful blog post<\/span><\/a><span style=\"font-weight: 400;\">, comparing BeanShell against other PostProcessors using Groovy and JavaScript:<\/span><\/p>\n<p><a href=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Screen-Shot-2017-06-28-at-8.59.43-PM-min.png\"><img decoding=\"async\" class=\"wp-image-9296 size-full aligncenter\" src=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Screen-Shot-2017-06-28-at-8.59.43-PM-min.png\" alt=\"beanshell vs groovy test\" width=\"814\" height=\"182\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">We can clearly observe that Groovy results in outstanding performance where it reduces the time by half when executing on BSF Sampler (<\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Bean_Scripting_Framework\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Bean Scripting Framework<\/span><\/a><span style=\"font-weight: 400;\">) and nearly a quarter when executing on a JSR223 Sampler (what replaces BSF nowadays).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">More great aspects of Groovy are, for example, its syntax, which is pretty straightforward, enabling you to write everyday sentences rapidly. Another feature that is also very useful is the <\/span><a href=\"https:\/\/jmeter.apache.org\/usermanual\/functions.html#__groovy\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">__groovy()<\/span><\/a><span style=\"font-weight: 400;\"> function that was introduced in the 3.1 version of JMeter. This function allows us to evaluate Groovy code anywhere in the script where usual functions can be placed.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s take a look at an easy example just to make things clear, we have a certain variable:<\/span><\/p>\n<p><a href=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Screen-Shot-2017-06-28-at-9.05.47-PM-min.png\"><img decoding=\"async\" class=\"size-full wp-image-9297 aligncenter\" src=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Screen-Shot-2017-06-28-at-9.05.47-PM-min.png\" alt=\"Screen Shot 2017-06-28 at 9.05.47 PM-min\" width=\"625\" height=\"121\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">And then we would like to use that value in a simple http request as follows:<\/span><a href=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Screen-Shot-2017-06-29-at-8.58.25-PM-min-1.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/groovy-function-min.png\"><img decoding=\"async\" class=\"aligncenter wp-image-9319 size-full\" src=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/groovy-function-min.png\" alt=\"groovy function\" width=\"1330\" height=\"632\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">As you can see <b>__groovy()<\/b><span style=\"font-weight: 400;\"> function can be evaluated almost anywhere in the script, in this example we declared a variable with the text \u201cIt\u2019s Groovy Right?\u201d and then we applied a substring Groovy function to it and the result is being shown on the name of the sampler.<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Finally, another functionality that I found really interesting is that Groovy gives us the possibility of executing OS commands within the code using \u00a0<\/span><b>\u201cMy_command\u201d.execute() <\/b><span style=\"font-weight: 400;\">or if we want to maintain the output in jmeter.log, we can use <\/span><b>\u201cMy_command\u201d.execute().text <\/b><span style=\"font-weight: 400;\">like in the example below:<\/span><\/p>\n<p><a href=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/commandInGroovy-min.png\"><img decoding=\"async\" class=\"aligncenter wp-image-9320 size-full\" src=\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/commandInGroovy-min.png\" alt=\"command in groovy\" width=\"1349\" height=\"631\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">It may take some time to adapt to Groovy. Even so, I think that after reading this brief summary of its pros and its cons, you will seriously want to consider migrating your post processors right into Groovy, so you can take real advantage of the outstanding performance and new features that it has to offer.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We want to know: what are your experiences with Groovy?<\/span><\/p>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"Recommended_for_You\"><\/span><strong>Recommended for You<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"http:\/\/abstracta.us\/blog\/performance-testing\/gatling-tool-review-performance-tests-written-scala\/\">Gatling Tool Review for Performance Tests (Written in Scala)<\/a><br \/>\n<a href=\"https:\/\/abstracta.us\/blog\/performance-testing\/jmeter-response-assertions-how\/\">JMeter Response Assertions: How to Know What to Validate in an HTTP Response Request<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>See what makes Groovy, groovy. When running load tests in Apache JMeter, in many cases it&#8217;s necessary to choose a post processor\/scripting language for certain tasks, such as handling SampleResult variables, assigning dynamic names to samplers or just adding some logic to scripts. We have&#8230;<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[87,50],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.0.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apache Groovy vs BeanShell: Which is Best? | Abstracta<\/title>\n<meta name=\"description\" content=\"When running load tests in JMeter, you may need to choose a post processor\/scripting language. In this post, we&#039;ll compare two of them: Groovy vs BeanShell.\" \/>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Groovy vs BeanShell: Which is Best? | Abstracta\" \/>\n<meta property=\"og:description\" content=\"When running load tests in JMeter, you may need to choose a post processor\/scripting language. In this post, we&#039;ll compare two of them: Groovy vs BeanShell.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog about AI-powered quality engineering for teams building complex software | Abstracta\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AbstractaQA\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-29T03:40:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-05T21:20:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Groovy-vs-Beanshell-v2-min.png\" \/>\n\t<meta property=\"og:image:width\" content=\"560\" \/>\n\t<meta property=\"og:image:height\" content=\"315\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@AbstractaUS\" \/>\n<meta name=\"twitter:site\" content=\"@AbstractaUS\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/abstracta.us\/blog\/#website\",\"url\":\"https:\/\/abstracta.us\/blog\/\",\"name\":\"Blog about AI-powered quality engineering for teams building complex software | Abstracta\",\"description\":\"AI-powered quality engineering\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/abstracta.us\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/abstracta.us\/wp-content\/uploads\/2017\/06\/Screen-Shot-2017-06-28-at-8.59.43-PM-min.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/#webpage\",\"url\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/\",\"name\":\"Apache Groovy vs BeanShell: Which is Best? | Abstracta\",\"isPartOf\":{\"@id\":\"https:\/\/abstracta.us\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/#primaryimage\"},\"datePublished\":\"2017-06-29T03:40:58+00:00\",\"dateModified\":\"2025-05-05T21:20:49+00:00\",\"author\":{\"@id\":\"https:\/\/abstracta.us\/blog\/#\/schema\/person\/c68426aae266fb10c7db3f3d6af2a321\"},\"description\":\"When running load tests in JMeter, you may need to choose a post processor\/scripting language. In this post, we'll compare two of them: Groovy vs BeanShell.\",\"breadcrumb\":{\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/abstracta.us\/blog\/\",\"url\":\"https:\/\/abstracta.us\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/\",\"url\":\"https:\/\/abstracta.us\/blog\/performance-testing\/\",\"name\":\"Performance Testing\"}},{\"@type\":\"ListItem\",\"position\":3,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/\",\"url\":\"https:\/\/abstracta.us\/blog\/performance-testing\/apache-groovy-vs-beanshell-make-right-decision\/\",\"name\":\"Apache Groovy vs BeanShell: How to Make the Right Decision?\"}}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/abstracta.us\/blog\/#\/schema\/person\/c68426aae266fb10c7db3f3d6af2a321\",\"name\":\"Mat\\u00edas Fornara, Operation Manager at Abstracta\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/abstracta.us\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e3720307097a99a3775478ad6bd51352?s=96&d=blank&r=g\",\"caption\":\"Mat\\u00edas Fornara, Operation Manager at Abstracta\"},\"description\":\"Tech Lead &amp; Performance Engineer, Abstracta\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/posts\/9287"}],"collection":[{"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/comments?post=9287"}],"version-history":[{"count":31,"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/posts\/9287\/revisions"}],"predecessor-version":[{"id":17508,"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/posts\/9287\/revisions\/17508"}],"wp:attachment":[{"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/media?parent=9287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/categories?post=9287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abstracta.us\/blog\/wp-json\/wp\/v2\/tags?post=9287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}