DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Why and How To Integrate Elastic APM in Apache JMeter
  • Transitioning From Groovy to Kotlin for Gradle Android Projects
  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts
  • Why "Polyglot Programming" or "Do It Yourself Programming Languages" or "Language Oriented Programming" sucks?

Trending

  • Docker Model Runner: Streamlining AI Deployment for Developers
  • A Guide to Developing Large Language Models Part 1: Pretraining
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • Why High-Performance AI/ML Is Essential in Modern Cybersecurity
  1. DZone
  2. Coding
  3. Languages
  4. Apache Groovy vs BeanShell: How to Make the Right Decision?

Apache Groovy vs BeanShell: How to Make the Right Decision?

See what makes Groovy so groovy with this brief summary of its pros and cons and new features for improving performance.

By 
Federico Toledo user avatar
Federico Toledo
·
Jul. 11, 17 · Opinion
Likes (2)
Comment
Save
Tweet
Share
3.9K Views

Join the DZone community and get the full member experience.

Join For Free

When running load tests in Apache JMeter, in many cases it’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 several options to choose from, but in this post, we will look at two in particular: BeanShell vs Groovy and why we are partial to Groovy. But, instead of trying to convince you why we believe Groovy is the better choice, we’ll present the facts and let them speak for themselves!

BeanShell 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.

Apache Groovy, on the other hand, is a dynamic object-oriented programming language that can be used as a scripting language for the Java platform.

Let’s take a deeper look at the main characteristics of each:

BeanShell

  1. Supports for loops and foreach loops.
  2. Syntax for array initialization is similar to Java.
  3. BeanShell can’t run a script written for Groovy as it is based on JDK1.4, so it has no generic features.
  4. Execution environment is 1.4 or more, but doesn’t support generics.
  5. Doesn’t support writing a method with variable arguments or calling a method with variable arguments.
  6. Doesn’t 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(“0x80018000”);

Apache Groovy

  1. Groovy engine can run a script written for BeanShell.
  2. Supports generics and collections with generics. Also supports raw types e.g.> ArrayList str = new ArrayList().
  3. Supports calling methods with variable arguments, e.g. method(int…i).
  4. Supports primitive data types like int to assign 4 byte hexa-decimal values eg. int i = 0x80018000.
  5. 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’s done as int[] array = [1,2,3].
  6. Supports for loops and foreach loops, etc.
  7. Development and support: the Groovy language is constantly being developed, maintained, and supported.
  8. Java compatibility: valid Java code in 99% of cases will be valid Groovy code.
  9. Groovy scripts can be statically compiled providing near Java code performance.
  10. Native support for regular expressions, XML, JSON.
  11. Simplified work with files.

Perhaps one of the most important features that we have mentioned about Groovy is the fact that it’s statically compiled, which means that we can obtain top-notch performance, similar to what we would achieve using Java.

To see the difference in performance, we can take a look at the following chart from this helpful blog post, comparing BeanShell against other PostProcessors using Groovy and JavaScript:

beanshell vs groovy test

We can clearly observe that Groovy results in outstanding performance where it reduces the time by half when executing on BSF Sampler (Bean Scripting Framework) and nearly a quarter when executing on a JSR223 Sampler (what replaces BSF nowadays).

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 __groovy() 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.

Let’s take a look at an easy example just to make things clear, we have a certain variable:

Screen Shot 2017-06-28 at 9.05.47 PM-min

And then we would like to use that value in a simple HTTP request as follows:

groovy function

As you can see __groovy() function can be evaluated almost anywhere in the script, in this example we declared a variable with the text “It’s Groovy Right?” and then we applied a substring Groovy function to it and the result is being shown on the name of the sampler.

Finally, another functionality that I found really interesting is that Groovy gives us the possibility of executing OS commands within the code using “My_command”.execute() or if we want to maintain the output in jmeter.log, we can use “My_command”.execute().text like in the example below:

command in groovy

It may take some time to adapt to Groovy. Even so, I think that after reading this brief summary of its pros and 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.

We want to know: what are your experiences with Groovy?

Groovy (programming language) BeanShell Apache Groovy

Published at DZone with permission of Federico Toledo, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Why and How To Integrate Elastic APM in Apache JMeter
  • Transitioning From Groovy to Kotlin for Gradle Android Projects
  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts
  • Why "Polyglot Programming" or "Do It Yourself Programming Languages" or "Language Oriented Programming" sucks?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!