Comparison
Structured text vs function blocks: what decides scan time
Short answer
Neither form is inherently faster: both structured text and function block logic compile to executable code on the same CPU. Convert a representative section, record minimum, average and maximum task time for each build, and treat a small difference that does not repeat as inconclusive. Decide on instance state, parameter passing rules and maintainability; a function block's read-only inputs and write-only outputs often matter more than any measured timing change.

On this page
- Is structured text or a function block faster in a PLC?
- What actually sets your PLC scan time?
- How do you measure the same task before and after a conversion?
- What does a worked scan-time comparison look like?
- When is a scan-time difference real rather than noise?
- How does state behave differently in a function block instance?
- What limits parameter passing in a function block?
- Should you convert 100 to 200 lines on one small test?
- Questions asked
You converted a small structured text routine to function blocks, saw almost no change in scan time, and now wonder whether the next 100 to 200 lines are worth moving. Do not move them for speed. Structured text and function block logic both compile into executable instructions for the same CPU, so neither form is inherently faster, and a small measured difference that does not repeat proves nothing. Record the minimum, average and maximum task time for each build on your target PLC, compare the worst observed time against the task deadline, and make the conversion decision on instance state, parameter passing and maintainability. This article gives the measurement procedure, a worked example with the arithmetic, and the decision for each outcome.
Is structured text or a function block faster in a PLC? #
Neither form is inherently faster. Both structured text and function block logic are translated by the compiler into executable instructions on the same CPU, so the number that decides is the task time you measure on your target PLC, not the language the source uses.
The compiler, not the editor, produces the machine work. A text editor and a graphical editor sit in front of the same translation step, so an identical logical operation compiled from either form costs what its generated instructions cost. The same principle appears outside PLCs: an example from robot programming shows SWAIT logic is flexible but not inherently faster. What changes between the forms is how you express state, interfaces and reuse, and those differences are where the decision belongs.
What actually sets your PLC scan time? #
Scan time is set by the instructions your tasks actually execute, not by how the source is drawn or typed: conditional branches taken, block calls and their data handling, I/O service, and network reads and writes scheduled by the task configuration all land in the same measurement.
That has two practical consequences. First, converting code without changing the operations it performs usually moves the measurement by an amount you cannot distinguish from run-to-run variation. Second, code that looks similar can execute differently: which logic runs when follows the task type and configuration rather than the order the program units appear in the project, as explained in why the task type decides execution order, not POU order. Network traffic belongs to the same story; how the PLC scan services NETRX and NETWX network reads and writes shows where those transfers land inside the scan.
How do you measure the same task before and after a conversion? #
Use the controller's own task diagnostics, record the minimum, average and maximum task time for the original build, then re-record the identical statistics for the converted build with the rest of the program, the machine state and the operating conditions held unchanged.
Work the comparison as a fixed procedure:
- Confirm the two builds are functionally equivalent before reading a single number: same operations, same data types, same execution order, same state behavior. A timing comparison of two different programs measures the difference between the programs, not between the languages.
- Find the per-task timing figures in your controller's task configuration or online diagnostics. The menu names differ by vendor, but the statistic each controller reports is the same.
- Record minimum, average and maximum rather than whichever value favors the form you prefer.
- Repeat the whole measurement at least twice per build, so you know the run-to-run variation before you compare builds against each other.
What does a worked scan-time comparison look like? #
In an illustrative example, a routine measured a maximum task time of 4.80 ms as structured text and 4.86 ms as a function block, a difference of 0.06 ms that sat inside the run-to-run variation of the unchanged build, so timing decided nothing. The numbers are an example of the procedure, not a measurement from a named controller.
The setup and the readings #
One cyclic task with a 10 ms interval runs the routine, about 60 lines, plus the rest of the plant program. Each reading covers 100 consecutive scans of steady production:
| Build | Minimum | Average | Maximum |
|---|---|---|---|
| Original structured text, run 1 | 4.71 ms | 4.78 ms | 4.80 ms |
| Original structured text, run 2, unchanged rebuild | 4.72 ms | 4.79 ms | 4.84 ms |
| Converted function block | 4.73 ms | 4.80 ms | 4.86 ms |
The arithmetic #
- Maximum-to-maximum difference: 4.86 − 4.80 = 0.06 ms.
- As a share of the structured text maximum: 0.06 ÷ 4.80 × 100, which is about 1.3%.
- Run-to-run variation of the unchanged structured text build: 4.84 − 4.80 = 0.04 ms on the maximum. Most of the conversion difference is therefore indistinguishable from noise.
- Headroom in the worst observed scan: 10 ms − 4.86 ms = 5.14 ms, so the task used 48.6% of its interval at the worst point (4.86 ÷ 10 × 100).
Decision: the timing difference is inconclusive, so it neither commands the conversion nor forbids it, and the utilization figure leaves ample headroom against the deadline. The choice falls to the interface and maintainability criteria in the last section.
When is a scan-time difference real rather than noise? #
A difference is real when it repeats across separate runs of both builds and you can trace it to operations that actually changed; if the converted maximum falls inside the range the original build also produced, the measured difference is noise and no conclusion about the languages follows from it.
Trace it in this order:
- Re-run both builds at least twice. A real difference survives separate runs; a one-off reading does not.
- Trace the added cost to changed operations using the platform's execution or block diagnostics where they exist. Where the platform exposes none, isolate the changed section in a controlled test and compare task measurements without touching other program work.
- Compare the worst observed task time across all runs against the task deadline. If the worst time fits inside the deadline, the timing question is closed even when the difference repeats.
One caution when you tighten deadlines: shortening a task interval to chase response time can drop short input pulses that finish between scans, as covered in why a PLC misses short input pulses and how to catch them. And if the task carries a guard or emergency-stop related response, the deadline comes from the validated safety function and its risk assessment, not from either language form.
How does state behave differently in a function block instance? #
A function block instance keeps its internal variables and output values from one call to the next, while structured text outside an instance computes from its inputs and whatever you store yourself, and that state difference changes behavior, not just speed.
A function block type is a definition; each call site that declares an instance gets private data, so two drives served by one timer type hold independent timing values. Structured text logic that needs memory must hold it in variables you declare and manage yourself. Vendor documentation states this precisely: Omron's CX-Programmer guide to function blocks and structured text covers instance creation and the Smart FB Library for CS1, CJ1-H and CJ1M series CPUs. If you are unsure whether a piece of logic needs an instance at all, the two tests that decide between a function and a function block settle that question before you time anything.
What limits parameter passing in a function block? #
Function block interfaces are typed and directional: the STEP 7 block parameter rules, for example, state that an input parameter may only be read, an output parameter only written, and an in-out parameter both read and written, so a routine that writes to an input will not port directly.
The same directional rule appears across IEC 61131-3 environments: inputs are read-only to the block body, outputs are written only, and in-out variables are the one path the block can both read and modify. Two practical limits follow. First, code that freely reads and writes shared tags in structured text must be restructured into explicit interface parameters during conversion, and the wrappers or copies that interface needs can cost more engineering than any timing difference would save. Second, several platforms cannot pass a timer or instruction tag through a function block interface at all; if your structured text depends on that, the conversion is off, whatever the measurements say.
Should you convert 100 to 200 lines on one small test? #
No. Convert one representative section first, verify identical outputs for identical input and state sequences, record both builds' task statistics, and keep the conversion only if behavior matches and the interface and maintainability tradeoffs beat the structured text you already have.
| Decision input | Keeps structured text | Keeps the function block |
|---|---|---|
| Scan time | difference inconclusive, or structured text repeatedly faster | function block repeatedly faster and traced to real changed work |
| State | logic without memory between scans | algorithm needs per-instance data, such as one timer per drive |
| Reuse on parallel equipment | copies drift apart as edits accumulate | one block type, one instance per unit |
| Interface direction | routine reads and writes shared tags directly | clean read-only inputs and write-only outputs help review |
| Passing tags or instruction references | needed, and the block interface cannot carry them | supported cleanly on the target platform |
| Review and version control | text diffs cleanly in source control | graphical wiring resists diffing |
The decision for each case:
- Case 1, the difference repeats and the converted build's worst observed time breaks the deadline: keep the faster form or optimize the slow one. The deadline governs, and no style preference overrides it.
- Case 2, the difference is inconclusive, as in the worked example: decide from the table. Parallel drives or stations sharing one algorithm argue for the function block; sequential logic, direct tag access and clean source-control diffs argue for structured text.
- Case 3, the structured text relies on passing tags and the platform's block interface cannot carry them: stay in structured text regardless of timing.
For the wider language choice, when to use structured text instead of ladder logic in a PLC applies the same tradeoffs against ladder, and the maintainability argument is set out in a best-practice guide to PLC programming language selection and maintainability.
Questions asked
Do minimum and average task times matter as much as the maximum?
For capacity, use the maximum: the task must finish inside its interval on its worst scan. Minimum and average tell you how typical scans behave and help you judge run-to-run variation, but the worst observed task time is the number to compare against the task deadline.
Is a function block diagram network the same thing as a function block?
No. A function block diagram network is a graphical way to wire logic together; a function block is a program organization unit type with an instance that keeps its own data. You can call a function block instance from structured text, from ladder, or from a function block diagram network, and the instance semantics stay the same.
How many scans should I record before comparing two builds?
Record enough scans to cover the machine's normal cycles, for example 100 consecutive scans, and repeat the whole measurement at least twice per build. If the worst time from one run falls inside the range the other build also produced, the difference sits inside normal variation and does not decide the conversion.
Does the compiler change the comparison?
Yes. The compiler version and optimization settings on the target change the generated instructions for both forms. Record the software version and build settings with each timing reading, and re-measure after any compiler or firmware update rather than carrying an old result forward.


