Batch operations let you group multiple register or variable reads/writes into a single network request, dramatically improving throughput.

## SNPX batch : 80x faster

SNPX batch assignments read or write groups of data in a single command with constant ~2 ms execution time, regardless of how many items are in the batch.

**C# : SnpxBatch**
```csharp
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Common;
using UnderAutomation.Fanuc.Snpx.Assignment;

public class SnpxBatch
{
  public static void Main()
  {
    FanucRobot robot = new FanucRobot();

    ConnectionParameters parameters = new ConnectionParameters("192.168.0.1");
    parameters.Snpx.Enable = true;

    robot.Connect(parameters);

    /**/
    // --- Numeric registers batch ---
    var numBatch = robot.Snpx.NumericRegisters.CreateBatchAssignment(1, 100);
    float[] numValues = numBatch.Read();

    // --- Position registers batch ---
    var posBatch = robot.Snpx.PositionRegisters.CreateBatchAssignment(1, 50);
    Position[] positions = posBatch.Read();

    // --- String registers batch ---
    var strBatch = robot.Snpx.StringRegisters.CreateBatchAssignment(1, 20);
    string[] strings = strBatch.Read();

    // --- Flag registers batch ---
    var flagBatch = robot.Snpx.Flags.CreateBatchAssignment(1, 100);
    bool[] flags = flagBatch.Read();

    // --- Integer system variables batch ---
    var intBatch = robot.Snpx.IntegerSystemVariables.CreateBatchAssignment(
        new[] { "$RMT_MASTER", "$MCR.$GENOVERRIDE", "$SCR.$NUM_GROUP" });
    int[] intValues = intBatch.Read();

    // --- Digital signals batch ---
    bool[] sdiValues = robot.Snpx.SDI.Read(1, 200);

    // --- Numeric I/O batch ---
    ushort[] giValues = robot.Snpx.GI.Read(1, 50);

    // --- Re-read the same batch (reusable) ---
    float[] numValues2 = numBatch.Read();
    /**/
  }
}
```

**Python : SnpxBatch**
```python
from underautomation.fanuc.fanuc_robot import FanucRobot
from underautomation.fanuc.connection_parameters import ConnectionParameters

# Create a robot instance
robot = FanucRobot()

# Configure connection parameters
parameters = ConnectionParameters("192.168.0.1")
parameters.snpx.enable = True

# Connect to the robot
robot.connect(parameters)

##
# --- Numeric registers batch ---
num_batch = robot.snpx.numeric_registers.create_batch_assignment(1, 100)
num_values = num_batch.read()

# --- Position registers batch ---
pos_batch = robot.snpx.position_registers.create_batch_assignment(1, 50)
positions = pos_batch.read()

# --- String registers batch ---
str_batch = robot.snpx.string_registers.create_batch_assignment(1, 20)
strings = str_batch.read()

# --- Flag registers batch ---
flag_batch = robot.snpx.flags.create_batch_assignment(1, 100)
flags = flag_batch.read()

# --- Integer system variables batch ---
int_batch = robot.snpx.integer_system_variables.create_batch_assignment(
    ["$RMT_MASTER", "$MCR.$GENOVERRIDE", "$SCR.$NUM_GROUP"])
int_values = int_batch.read()

# --- Digital signals batch ---
sdi_batch = robot.snpx.sdi.create_batch_assignment(1, 200)
sdi_values = sdi_batch.read()

# --- Numeric I/O batch ---
gi_batch = robot.snpx.gi.create_batch_assignment(1, 50)
gi_values = gi_batch.read()

# --- Re-read the same batch (reusable) ---
num_values2 = num_batch.read()
##
```

### Performance comparison

| Method | 80 position registers | Time |
|--------|----------------------|------|
| Individual reads | 80 × `PositionRegisters.Read()` | ~160 ms |
| Batch read | 1 × `BatchAssignment.Read()` | ~2 ms |

See also: [SNPX Batch reading](/fanuc/documentation/snpx-batch)

## CGTP batch : Multiple types in one request

CGTP batch variables combine registers, strings, positions, and system variables in a single HTTP request:

**C# : OptimizePerformanceBatchOperationsCgtp**
```csharp
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Cgtp;
using UnderAutomation.Fanuc.Cgtp.BatchVariables;

public class OptimizePerformanceBatchOperationsCgtp
{
    static void Main()
    {
        FanucRobot robot = new FanucRobot();
        robot.Connect("192.168.0.1");

        /**/
        // Create a batch
        var batch = new CgtpBatchVariables();

        // Add different types
        batch.AddNumericRegister(1);
        batch.AddNumericRegister(2);
        batch.AddStringRegister(1);
        batch.AddPositionRegister(1);
        batch.AddVariable("$RMT_MASTER");

        // Read all at once
        CgtpBatchReadResult result = robot.Cgtp.ReadBatchVariables(batch);

        // Write batch with values
        var writeBatch = new CgtpBatchVariables();
        writeBatch.AddNumericRegisterAsReal(1, "Speed", 50.0);
        writeBatch.AddNumericRegisterAsInteger(2, "Counter", 0);
        writeBatch.AddStringRegisterWithValue(1, "Status", "Running");
        robot.Cgtp.WriteBatchVariables(writeBatch);
        /**/
    }
}
```

**Python : OptimizePerformanceBatchOperationsCgtp**
```python
from underautomation.fanuc.fanuc_robot import FanucRobot

robot = FanucRobot()
robot.connect("192.168.0.1")

##
# Create a batch
batch = robot.cgtp.create_batch_variables()

# Add different types
batch.add_numeric_register(1)
batch.add_numeric_register(2)
batch.add_string_register(1)
batch.add_position_register(1)
batch.add_variable("$RMT_MASTER")

# Read all at once
result = robot.cgtp.read_batch_variables(batch)

# Write batch with values
write_batch = robot.cgtp.create_batch_variables()
write_batch.add_numeric_register_as_real(1, "Speed", 50.0)
write_batch.add_numeric_register_as_integer(2, "Counter", 0)
write_batch.add_string_register_with_value(1, "Status", "Running")
robot.cgtp.write_batch_variables(write_batch)
##
```

See also: [CGTP Registers & variables](/fanuc/documentation/cgtp-registers-variables)

## Best practices

1. **Reuse batch assignments**: Create them once, call `Read()` repeatedly
2. **Group related data**: Combine registers, I/O, and variables that you always need together
3. **Use SNPX for speed-critical paths**: ~2 ms vs ~50 ms for CGTP
4. **Use CGTP for mixed types**: CGTP batch can combine registers, variables, and positions in one request
5. **Monitor polling cycles**: Batch reads enable sub-10ms polling cycles with SNPX

## Protocol comparison

| Feature | SNPX Batch | CGTP Batch |
|---------|-----------|------------|
| **Execution time** | ~2 ms (constant) | ~50 ms |
| **Numeric registers** | Yes | Yes |
| **Position registers** | Yes | Yes |
| **String registers** | Yes | Yes |
| **Flags** | Yes | No |
| **System variables** | Yes | Yes |
| **Digital I/O** | Yes | No |
| **Numeric I/O** | Yes | No |
| **Read + Write** | Read only | Read + Write |
| **Mixed types** | One type per batch | Multiple types |