Skip to content

__counter

JMeter __counter function reference: syntax, parameters, and practical examples for parameterizing test plans with dynamic values.

Difficulty
intermediate
Guide type
reference
Estimated read time
1 min read
Last verified version
Verified JMeter 5.6

Also documented in context in the full Functions and Variables reference.

TL;DR: __counter returns an incrementing integer, either per-thread (independent counters) or global (shared across all threads) โ€” useful for unique sequential IDs without a CSV file.

The counter generates a new number each time it is called, starting with 1 and incrementing by +1 each time. The counter can be configured to keep each simulated userโ€™s values separate, or to use the same counter for all users. If each userโ€™s values is incremented separately, that is like counting the number of iterations through the test plan. A global counter is like counting how many times that request was run.

The counter uses an integer variable to hold the count, which therefore has a maximum of 2,147,483,647.

The counter function instances are completely independent. The global counter - โ€œFALSEโ€ - is separately maintained by each counter instance.

Multiple __counter function calls in the same iteration wonโ€™t increment the value further.

If you want to have a count that increments for each sample, use the function in a Pre-Processor such as User Parameters.

NameRequiredDescription
First argumentYesTRUE if you wish each simulated userโ€™s counter to be kept independent and separate from the other users. FALSE for a global counter.
Second argumentNoA reference name for reusing the value created by this function. Stored values are of the form \${refName}. This allows you to keep one counter and refer to its value in multiple places.
${__counter(TRUE)} โ†’ per-thread counter, starts at 1 for each thread
${__counter(FALSE,cnt)} โ†’ global counter shared by all threads, saved to "cnt"

Multiple __counter calls within the same iteration donโ€™t increment further โ€” only one increment per iteration, no matter how many times you reference it. If you need one increment per sample instead, put the counter logic in a Pre-Processor. For genuinely unique (not just sequential) values, see __UUID.

On this page