JMeter functions are built-in expressions you write as ${__name(arguments)} in almost any field of a test plan. JMeter replaces each call with its result when the element runs: ${__time(yyyy-MM-dd,)} becomes today’s date, ${__Random(1,100,)} a random number, ${__P(env,staging)} a property passed on the command line or its default.
We put more than 30 function calls into one request body, ran it in JMeter 5.6.3 with three threads for two iterations, and recorded what the server received. Every function returned what the manual describes. What catches people out is everything around the calls: when a call is evaluated, what happens to a misspelled name, and how much CPU the scripting functions cost.
Key Takeaways
- The syntax is
${__functionName(arg1,arg2,variableName)}. Many functions take an optional last argument that also stores the result in a variable. - A function in an ordinary field runs every time the element runs. In a User Defined Variables element it runs once, at the start of the test, and every thread sees the same value.
- A misspelled function or an undefined variable raises no error: JMeter sends the text as written,
${__nosuchfunction(1)}included. __Pand__propertyread values passed with-Jon the command line, and fall back to the default you give them.__jexl3and__groovyare cheap enough for a loop. In our 20,000-call test,__javaScriptcost 34 CPU seconds more than an empty loop, against 1.6 for__groovy.
What are JMeter functions?
A JMeter function is a call written inside a field, such as a URL path, a request body, a header value or a timer’s delay, that JMeter evaluates when the element runs. Function names start with two underscores to keep them apart from your own variables. Arguments are separated by commas, a comma inside an argument is escaped as a backslash followed by a comma, and functions can be nested inside each other.
The general form is ${__functionName(arguments)}. A function without arguments can drop the parentheses, so ${__UUID} and ${__UUID()} are the same. Many functions accept a variable name as their last argument and store the result there as well, so the value can be reused later in the same thread: ${__Random(1,100,rnd)} returned 8 in one of our requests, and ${rnd} a few lines later in the same body also printed 8.
JMeter 5.6.3 registers 49 functions. In the GUI, Tools > Function Helper Dialog lists them, takes the arguments and generates the call for you to copy, which is the quickest way to check argument order. The manual’s functions page describes each one.
Which JMeter functions are most useful?
The everyday set covers time, random data, counters, properties and small transformations. The table shows each call as we wrote it and the value one thread sent on 30 November 2026, at about 17:01 local time. Calls that store a value take a variable name as the last argument; leaving it empty, as in most rows below, just returns the value.
| Call | What it does | Value sent |
|---|---|---|
${__time()} | Current time in milliseconds since 1970 | 1796050917385 |
${__time(/1000,)} | Same, in seconds | 1796050917 |
${__time(yyyy-MM-dd'T'HH:mm:ss.SSS,)} | Current time in a date format | 2026-11-30T17:01:57.385 |
${__timeShift(yyyy-MM-dd,,P1D,,)} | Now plus one day | 2026-12-01 |
${__Random(1,100,rnd)} | Random integer from 1 to 100, also stored in rnd | 8 |
${__RandomString(8,abcdef0123456789,)} | 8 characters picked from the list | ce5f7b54 |
${__RandomDate(yyyy-MM-dd,2026-01-01,2026-12-31,,)} | Random date in a range | 2026-04-18 |
${__UUID()} | Random UUID | 5325d227-fc10-4511-b068-732410873099 |
${__threadNum} | Number of the thread within its group | 3 |
${__counter(TRUE,)} | Counter per thread | 1 |
${__counter(FALSE,)} | Counter shared by all threads | 2 |
${__P(env,staging)} | Property env, or staging if it is not set | staging |
${__intSum(2,3,)} | Sum of integers | 5 |
${__groovy(vars.get('rnd').toInteger() * 2,)} | Result of a Groovy expression | 16 |
${__jexl3(${rnd} > 50 ? "high" : "low",)} | Result of a JEXL expression | low |
${__digest(SHA-256,hello,,,)} | Hash of a string | 2cf24dba5f...38b9824 |
${__urlencode(a b&c=d)} | URL-encoded string | a+b%26c%3Dd |
${__changeCase(hello world,UPPER,)} | String in upper case | HELLO WORLD |
${__dateTimeConvert(2026-11-30,yyyy-MM-dd,dd/MM/yyyy,)} | Date converted between formats | 30/11/2026 |
${__V(user_${__threadNum})} | Value of a variable whose name is built at run time | carol |
${__isVarDefined(rnd)} | Whether a variable exists | true |
The __V row needs a word. With variables user_1 to user_3 set to alice, bob and carol, ${__V(user_${__threadNum})} gave thread 3 the value carol. Writing the same thing without __V, as ${user_${__threadNum}}, sent that text literally, because JMeter does not resolve a variable whose name contains another reference.
For values that must be unique per request, such as order numbers, our post on generating unique IDs in JMeter compares __UUID, __counter and the Counter element, and explains why __Random repeats.
How do you get the current date and time in JMeter?
Use ${__time(format,)} for the current time and ${__timeShift(format,date,shift,,)} for a time before or after it. Without a format, __time returns milliseconds since 1970; /1000 gives seconds; any Java date pattern, such as yyyy-MM-dd, gives formatted text. The shift in __timeShift is an ISO-8601 duration: P1D adds a day, -P7D subtracts a week, PT2H adds two hours.
Our run on 30 November gave these results:
${__timeShift(yyyy-MM-dd,,P1D,,)}returned 2026-12-01, tomorrow.${__timeShift(yyyy-MM-dd,,-P7D,,)}returned 2026-11-23, a week earlier.${__timeShift(HH:mm,,PT2H,,)}returned 19:01 when the clock said 17:01.${__timeShift(yyyy-MM-dd,2026-11-30,P30D,,)}shifted a fixed date instead of now: 2026-12-30.
Two related functions round out the set. __dateTimeConvert turns a date from one format into another, for example the yyyy-MM-dd date a previous response returned into the dd/MM/yyyy form the next request expects. __RandomDate picks a date between two bounds; leave the start empty and it starts from now. In a booking test, a check-in date of ${__timeShift(yyyy-MM-dd,,P14D,,)} stays two weeks ahead however long the script lives, where a hard-coded date breaks the day it passes.
How do you generate random numbers and strings in JMeter?
${__Random(min,max,)} returns a whole number between the two bounds, and ${__RandomString(length,characters,)} builds a string from the characters you list. ${__RandomDate(format,start,end,,)} picks a date, and ${__UUID()} returns a random UUID. All four run again on every call, so each request, thread and iteration gets a fresh value.
In our six requests, ${__Random(1,100,rnd)} returned 8, 54, 45, 100, 58 and 88, so the maximum itself came up. Random is not unique: with a small range, two threads will draw the same number sooner or later, so use __UUID or a counter for IDs. Random also makes runs hard to compare, because each run sends different data; for repeatable tests, keep the data in a CSV file instead, which our guide to parameterization in JMeter covers.
To vary the path through a test rather than the data, use a Random Controller or a Throughput Controller rather than a function in a field. Those are covered in our guide to JMeter logic controllers.
How do __P and __property read values from the command line?
${__P(name,default)} returns the JMeter property called name, which you set with -Jname=value on the command line or in user.properties, and returns the default when the property does not exist, or 1 when no default is given. ${__property(name,,default)} does the same with an extra middle argument that stores the result in a variable. Properties are global: every thread reads the same value.
Without -Jenv, our two calls, ${__P(env,staging)} and ${__property(env,,local)}, returned their defaults, staging and local. Run with -Jenv=prod, all six requests sent prod from both. This is the usual way to point one test plan at different environments or set its load from a CI pipeline, for example ${__P(threads,10)} in a thread group’s user count, and it is how the User Defined Variables guide overrides values from the command line.
${__setProperty(name,value,)} writes a property, which makes it the standard way to pass a value from one thread group to another, since variables stay inside their thread. Two things to know. The call returns an empty string, so it adds nothing to the field it sits in; a third argument of true makes it return the property’s previous value instead. And with several threads writing the same property, the last one wins: each of our three threads set lastUser to user- plus its thread number, and a teardown thread group read user-2.
When is a JMeter function evaluated?
A function in a sampler, timer or config field is evaluated each time that element runs, separately in each thread. A function in a User Defined Variables element is evaluated once, when the test starts, and the result is shared by every thread. A function in a cached JSR223 script runs once in each thread, and the script keeps that first value.
Our run showed each case:
${__Random(1,1000)}in a User Defined Variables element gave 220 to all three threads in both iterations, and a__timecall there gave 17:01:57.102 to all six requests.- The same functions in the request body gave a different value in every one of the six requests.
${__counter(TRUE,)}counted 1 and 2 in each thread, while${__counter(FALSE,)}counted 1 to 6 across all of them.${__StringFromFile(lines.txt,,,)}read the next line of a three-line file for whichever thread asked: over six calls each line came up twice, and which line a thread got depended on timing.
The JSR223 case is the risky one, because it fails silently. A ${__Random(1,1000000)} written inside a JSR223 Sampler’s script with “Cache compiled script if available” ticked gave the three threads the same three numbers on their second iteration as on their first. Pass the call through the Parameters field instead, as our JMeter JSR223 and Groovy guide shows with timings.
What happens when a function name or variable is wrong?
Nothing visible: JMeter sends the text as you wrote it. A call to a function that does not exist, ${__nosuchfunction(1)}, reached our server as the literal string, and so did ${missing}, a variable never defined. The sample passed, the run ended normally, and neither showed as an error in the console summary.
This is why a typo such as ${__Ramdom(1,100)} or a wrong variable name can survive in a test plan for weeks. The server receives an odd value, often answers 200 anyway, and the load test measures the wrong thing. Three habits help:
- Check a request in a View Results Tree listener on a short run before any load test, and search the request for
${. - Add a Response Assertion where a bad value would show, or use
${__isVarDefined(name)}, which returned true for ourrndvariable and false for one that was never set. - Build each call with the Function Helper Dialog rather than typing it.
Which scripting function is fastest: __groovy, __jexl3 or __javaScript?
__jexl3 is the fastest, with __groovy close behind, and both are cheap enough for a loop; __javaScript is not. In our test of 20,000 calls in one thread, __jexl3 used no measurable extra CPU over an empty loop, __groovy added 1.6 CPU seconds, and __javaScript added 34 seconds and needed six times the memory. The manual itself advises __jexl3 or __groovy over __javaScript for tests with many threads.
We put each function into the pause duration of a Flow Control Action, looped it 20,000 times in one thread, and measured the whole JMeter process with the operating system’s time command, twice per function, in two interleaved rounds. A Groovy call writing a log line confirmed the function ran once per loop: 50 loops, 50 lines.
| Field contains | CPU seconds, 20,000 calls | Extra over empty loop | Wall time | Peak memory |
|---|---|---|---|---|
0 (empty loop) | 2.65 | none | 2.4 s | 0.23 GB |
${__Random(0,0,)} | 2.42 | none measurable | 2.4 s | 0.23 GB |
${__jexl3(0,)} | 2.68 | none measurable | 2.4 s | 0.23 GB |
${__groovy(0,)} | 4.26 | 1.6 s | 2.9 s | 0.41 GB |
${__javaScript(0,)} | 36.61 | 34.0 s | 17.0 s | 1.42 GB |
The 2.6 seconds of the empty loop are mostly JMeter starting up. A shorter run of 2,000 calls showed that a good part of the Groovy cost is a one-time charge for the first call, so its cost per call is smaller than 1.6 seconds divided by 20,000. On Java 11, JMeter’s __javaScript uses the Nashorn engine by default. Other processes kept the machine’s load average between 9 and 14 during the runs, so read the table as orders of magnitude.
Using JMeter functions on LoadFocus
JMeter functions are part of the test plan, so they run in the cloud as they do on your machine. LoadFocus runs uploaded .jmx files on JMeter engines from its cloud regions, accepts CSV data files uploaded with the plan, and lets you set the users, ramp-up and duration for each thread group in the browser.
There is no field for -J command-line properties when you start a LoadFocus JMeter test, so every ${__P(name,default)} in the plan returns its default there, and a __P call without a default returns 1. Give each one a default that is right for the cloud test, or move the value into a CSV file. Before uploading, the free JMeter script validator checks a .jmx for missing or broken elements and for configuration that would make the run behave unexpectedly.
Frequently Asked Questions
What are functions in JMeter?
They are built-in expressions, such as the time and random functions, that you write in almost any field of a test plan as a dollar sign, braces and a name starting with two underscores. JMeter replaces each one with its result when the element runs, so a request can carry the current date, a random number or a value passed on the command line.
How do I get the current date in JMeter?
Use the time function with a Java date format, for example yyyy-MM-dd as its first argument. Without a format it returns milliseconds since 1970. For a date in the future or the past, use the timeShift function with an ISO-8601 duration such as P1D for one day ahead or -P7D for one week back.
How do I generate a random number in JMeter?
Use the Random function with a minimum and a maximum, and optionally a variable name to store the result. It returns a new number on every call. Random numbers repeat, so use the UUID function or a counter when each value must be unique.
What is the difference between __P and __property in JMeter?
Both read a JMeter property and return a default when it is missing. __P takes the name and the default. __property takes the name, an optional variable name to store the result in, and the default. Set the property with -J on the command line or in user.properties.
Why does my JMeter function show up as plain text in the request?
JMeter sends a call it cannot resolve exactly as written, without an error. The usual causes are a misspelled function name, a missing underscore, wrong brackets or a variable that was never defined. Check the request in View Results Tree and look for a dollar sign followed by a brace.
Sources
- Functions and variables: Apache JMeter User’s Manual, chapter 20, jmeter.apache.org/usermanual/functions.html, version 5.6.3, read 30 November 2026 (syntax, comma escaping, Function Helper Dialog, the advice to prefer
__jexl3or__groovyover__javaScript). - JSR223 script caching: Apache JMeter User’s Manual, Component Reference, JSR223 Sampler, jmeter.apache.org/usermanual/component_reference.html, read 30 November 2026.
- Function count (49 registered names, listed through JMeter’s own
CompoundVariableclass) and the Nashorn default: the JMeter 5.6.3 jars andbin/jmeter.properties, jars checked against the SHA-1 checksums on Maven Central, 30 November 2026. - LoadFocus JMeter runs and the script validator: loadfocus.com/jmeter-load-testing and loadfocus.com/jmeter-script-validator, read 30 November 2026.
- Test runs: Apache JMeter 5.6.3 in non-GUI mode on Java 11.0.19, against a local Node.js 23.11.1 server that recorded every request body, on an Apple M1 Max, 30 November 2026. CPU time and peak memory come from
/usr/bin/time -l, two alternating runs per function. Timings show patterns, not benchmarks.