Skip to content

Functions Usage

Since OctoPerf operates JMeter in the background, it is also possible to use JMeter functions. Functions are shortcuts you can use to avoid adding a script block into your virtual user. The same result can be achieved programmatically but they make life easier by handling a lof of common situations.


When a requests sends a timestamp in milliseconds, you can just replace it with: ${__time()} This way, the current timestamp will be send every time instead of the recorded/original value. It is also possible to get a timestamp in seconds using: ${__time(/1000)} Or many other date formats, be sure to check its documentation page for more details.


The Timeshift function can generate date and times as well but is mostly used to place an offset on a date.

Attribute Description
Format The date output format, see DateTimeFormatter documentation for more details.
Date to shift The date you want to shift using Format set in first attribute. If empty, current date is used instead.
value to shift Indicates the amount of time to shift. The format is PnDTnHnMn.nS it can be preceded by a - for negative date shifts. More info can be found in the documentation.
Locale to use for format The string format of a locale. See the locale documentation for more info. If empty, the function will default toen_EN.
Name of variable Name of a variable in which the result will be stored for further use.


Contrary to what the documentation may suggest, to use negative date increments for time intervals of an hour or less, it is mandatory to use PT instead of just P. Ex: -PT1H.

Here are some examples with the current date 2021-02-10 13:31:16 :

Timeshift Result
${__timeShift(,,,,)} 1612960276007
${__timeShift(dd/MM/yyyy,,,,)} 10/02/2021
${__timeShift(y-MM-dd HH:mm:ss,,,,)} 2021-02-10 13:31:16
${__timeShift(dd/MM/yyyy,,P1D,,)} 11/02/2021
${__timeShift(dd-MM-y-HH-mm-ss,,P1DT1H1M,,)} 11-02-2021-14-32-16
${__timeShift(dd-MM-y-HH-mm-ss,,-PT1H,,)} 10-02-2021-12-31-16
${__timeShift(y MMM dd HH:mm:ss,,,fr_FR,)} 2021 févr. 10 13:31:16

CSV Read

When the CSV variables are not enough for your requirements you can manually parse a CSV file using functions:


Check out our example on the CSV variable page for more details.


This is meant to implement a counter that can be shared between all users running. It will only increment when moving to the next iteration/loop of each user. Which means you can use it several times in a virtual user and its value remains consistent (at least until you get to the next iteration). It can be used this way: ${__counter}

More details can be found on its documentation page here.


A simple random function with a min and max value: ${__Random(0,10)}. You can store the random value in a variable for further use: ${__Random(0,10, variable)}.

Other random functions include the random date: ${__RandomDate()} and the random string (with length): ${__RandomString(5)}


Properties are values shared among all users running inside JMeter. The value of property propertyName can be used like this: ${__P(propertyName)}.

This can be used in combination with the runtime properties to control your scripts in real time while the test is running.

Nested variables

The ${...} syntax used for variables does not allow nested variables (otherwise only one of them will be replaced). When this happens we must use the __V function.


We already have a detailed example of a situation where this can be useful on the while page.

Quick script

It is sometime required to use a scripting language to deal with unusual behaviors. Although it is possible to write JSR samplers/pre/postprocessors it is sometimes easier to just go for a quick one line script just where it is required. You can call it by using the language name like this:

${__javaScript(...)} or ${__groovy(...)}

It can be as easy as a simple condition for your while/if:


Or you could compute a value:



If you make use of groovy, avoid using the ${...} syntax for variables. Otherwise since the result may differ on each execution your script cannot be cached and may result in poor performance.


Sometimes strings must be encoded to be send over the network. Typically in a form-urlencoded post for instance. A good way to take care of that is to use the __urlencode function.

For example ${__urlencode(string th@t requires "encoding")} will return string+th%40t+requires+%22encoding%22

Note how the spaces were encoded as +, if you prefer to have them encoded as %20 you can use another function:


Our correlation rules will use this function when encoding is set to Url encode.


__urldecode will do the exact opposite if you need to put the string back in a more readable format.