# Begin

> Begin profiling a piece of code with a custom label defined by this instance of CustomSampler.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Profiling](/engine/6000.6/script-reference/unityengine/profiling.md)
* **Assembly:** UnityEngine.CoreModule

## Begin()

Begin profiling a piece of code with a custom label defined by this instance of [CustomSampler](/engine/6000.6/script-reference/unityengine/profiling/customsampler.md).

```csharp
[Conditional("ENABLE_PROFILER")]
public void Begin()
```

### Remarks

This will show up in the Profiler hierarchy.

```csharp
using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour
{
    CustomSampler sampler;
    void Start()
    {
        sampler = CustomSampler.Create("MyCustomSampler");
    }

    void Update()
    {
        sampler.Begin();
        // do something that takes a lot of time
        sampler.End();
    }
}
```

Profiler.BeginSample is conditionally compiled away using ConditionalAttribute. Thus it will have zero overhead, when it is deployed in non-Development Build.

Additional Resources: [CustomSampler.End](/engine/6000.6/script-reference/unityengine/profiling/customsampler/end.md), [CustomSampler.Create](/engine/6000.6/script-reference/unityengine/profiling/customsampler/create.md), [ProfilerCPU](/engine/6000.6/manual/analysis/profiler/visualizing-data/cpu.md).

## Begin(Object)

Begin profiling a piece of code with a custom label defined by this instance of [CustomSampler](/engine/6000.6/script-reference/unityengine/profiling/customsampler.md).

```csharp
[Conditional("ENABLE_PROFILER")]
public void Begin(Object targetObject)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)):&#x20;

### Remarks

This will show up in the Profiler hierarchy.

```csharp
using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour
{
    CustomSampler sampler;
    void Start()
    {
        sampler = CustomSampler.Create("MyCustomSampler");
    }

    void Update()
    {
        sampler.Begin();
        // do something that takes a lot of time
        sampler.End();
    }
}
```

Profiler.BeginSample is conditionally compiled away using ConditionalAttribute. Thus it will have zero overhead, when it is deployed in non-Development Build.

Additional Resources: [CustomSampler.End](/engine/6000.6/script-reference/unityengine/profiling/customsampler/end.md), [CustomSampler.Create](/engine/6000.6/script-reference/unityengine/profiling/customsampler/create.md), [ProfilerCPU](/engine/6000.6/manual/analysis/profiler/visualizing-data/cpu.md).
