{"id":98,"date":"2024-09-29T12:00:00","date_gmt":"2024-09-29T12:00:00","guid":{"rendered":"https:\/\/unity3dperformance.com\/?p=98"},"modified":"2024-09-29T18:17:19","modified_gmt":"2024-09-29T18:17:19","slug":"profiler-beginsample-unity3d-optimization","status":"publish","type":"post","link":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/","title":{"rendered":"How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Performance optimization in Unity3D is a crucial aspect of game development.<a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Profiling.Profiler.BeginSample.html\"> <code>Profiler.BeginSample<\/code><\/a> is one of the powerful tools that allows developers to closely monitor and analyze script performance. This enables a better understanding of which elements of the game may require optimization, leading to improved performance and smoother gameplay.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Profiler.BeginSample?<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Profiler.BeginSample<\/strong> is a method in Unity3D that allows tracking and recording the execution time of specific code segments. This enables developers to see how long it takes to execute a given function or script, helping to identify performance bottlenecks. Using this function is particularly useful in larger projects where even minor delays can affect the overall gaming experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why is Profiler.BeginSample Important?<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In large Unity3D projects where multiple systems are running simultaneously, it\u2019s easy to overlook inefficient code fragments that can slow down the game. Using Profiler.BeginSample allows for detailed analysis, enabling effective identification and optimization of these areas. Reducing the execution time of key functions translates to better game performance, higher FPS, and a more responsive gameplay experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Use Profiler.BeginSample for Optimization<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To use <code>Profiler.BeginSample<\/code> in Unity3D, follow these steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Add BeginSample<\/strong><br>Identify the specific code segment you want to profile. This could be a function or a loop where you suspect performance issues may arise. At the beginning of this segment, insert the following line of code: <code>Profiler.BeginSample(\"SampleName\")<\/code><br>Here, replace <code>\"SampleName\"<\/code> with a descriptive label that reflects the purpose of the code being profiled. This name will help you recognize the sample later in the Profiler window.<br><\/li>\n\n\n\n<li><strong>Add EndSample<\/strong><br>Once the execution of the code segment is complete, you need to mark the end of the profiling session. Immediately after the code you wish to profile, add the line: <code>Profiler.EndSample();<\/code><br>This will conclude the timing for the specific segment, allowing the Profiler to log the duration and performance metrics associated with that code execution.<br><\/li>\n\n\n\n<li><strong>Analyze the Results<\/strong><br>With the profiling segments added, run your game and open the Unity Profiler. You will be able to see the performance data collected for each labeled sample. By examining the results, you can identify which segments of your code are consuming the most time and pinpoint any potential bottlenecks that may require further optimization.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example of Using Profiler.BeginSample:<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Before Using Profiler.BeginSample<\/strong><br>Before adding <code>Profiler.BeginSample<\/code>, the Profiler provides general performance data, but we cannot precisely examine individual code segments. In this example, we have a function that processes a heavy operation in the game. Here\u2019s the code snippet before implementing <code>Profiler.BeginSample<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"using UnityEngine;\n\npublic class Example : MonoBehaviour\n{\n    private void Update()\n    {\n        PerformHeavyOperation();\n    }\n\n    private void PerformHeavyOperation()\n    {\n        for (int i = 0; i &lt; 1000000; i++) { }\n    }\n}\n\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">using<\/span><span style=\"color: #D8DEE9FF\"> UnityEngine<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">public<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">class<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Example<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> MonoBehaviour<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">private<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">void<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">Update<\/span><span style=\"color: #ECEFF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #88C0D0\">PerformHeavyOperation<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">private<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">void<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">PerformHeavyOperation<\/span><span style=\"color: #ECEFF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> i <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1000000<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i<\/span><span style=\"color: #81A1C1\">++<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><br><strong>Profiling Results Before Adding BeginSample:<\/strong><br>The following image shows the profiling results from the Profiler before applying <code>Profiler.BeginSample<\/code>. As seen, we get an overview of the performance metrics, but it lacks the granularity needed to identify specific bottlenecks.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Profiling results before adding BeginSample<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code After Using Profiler.BeginSample<\/strong><br>After adding <code>Profiler.BeginSample<\/code> in key areas of the code, we can more accurately monitor the execution time of specific functions. This allows for more detailed data regarding the performance of individual script segments. Here\u2019s the updated code:<br><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"using UnityEngine;\nusing UnityEngine.Profiling;\n\npublic class Example : MonoBehaviour\n{\n    private void Update()\n    {\n        Profiler.BeginSample(&quot;Heavy Operation&quot;);\n        PerformHeavyOperation();\n        Profiler.EndSample();\n    }\n\n    private void PerformHeavyOperation()\n    {\n        for (int i = 0; i &lt; 1000000; i++) { }\n    }\n}\n\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">using<\/span><span style=\"color: #D8DEE9FF\"> UnityEngine<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">using<\/span><span style=\"color: #D8DEE9FF\"> UnityEngine<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">Profiling<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">public<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">class<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Example<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> MonoBehaviour<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">private<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">void<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">Update<\/span><span style=\"color: #ECEFF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">Profiler<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">BeginSample<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Heavy Operation<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #88C0D0\">PerformHeavyOperation<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">Profiler<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">EndSample<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">private<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">void<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">PerformHeavyOperation<\/span><span style=\"color: #ECEFF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> i <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1000000<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i<\/span><span style=\"color: #81A1C1\">++<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Profiling Results After Using BeginSample:<\/strong><br>With <code>Profiler.BeginSample<\/code> implemented, we can now get a clearer view of how long it takes to process the enemies. Below is the updated profiling result from the Profiler after applying <code>BeginSample<\/code>, which shows the execution time for the &#8220;Process Enemies&#8221; segment specifically.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-14-1024x536.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Profiling results after using BeginSample to analyze selected code segments.<\/figcaption><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using <code>Profiler.BeginSample<\/code> provides valuable insights into the execution time of specific code segments. By comparing the profiling results before and after implementing this method, developers can better understand where performance bottlenecks may occur and take appropriate action to optimize their code effectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Performance optimization in Unity3D is a crucial aspect of game development. Profiler.BeginSample is one of the powerful tools that allows developers to closely monitor and analyze script performance. This enables a better understanding of which elements of the game may require optimization, leading to improved performance and smoother gameplay. What is Profiler.BeginSample? Profiler.BeginSample is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[23,18],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-unity-optimization","tag-code-optimization","tag-unity-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools - Unity3D Performance Blog<\/title>\n<meta name=\"description\" content=\"Learn how to use Profiler.BeginSample in Unity3D to optimize code performance by tracking and analyzing specific code segments. Improve game performance by identifying bottlenecks and optimizing execution time with these easy steps.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools - Unity3D Performance Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to use Profiler.BeginSample in Unity3D to optimize code performance by tracking and analyzing specific code segments. Improve game performance by identifying bottlenecks and optimizing execution time with these easy steps.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/\" \/>\n<meta property=\"og:site_name\" content=\"Unity3D Performance Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-29T12:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-29T18:17:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png\" \/>\n<meta name=\"author\" content=\"Rufi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rufi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/\",\"url\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/\",\"name\":\"How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools - Unity3D Performance Blog\",\"isPartOf\":{\"@id\":\"https:\/\/unity3dperformance.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png\",\"datePublished\":\"2024-09-29T12:00:00+00:00\",\"dateModified\":\"2024-09-29T18:17:19+00:00\",\"author\":{\"@id\":\"https:\/\/unity3dperformance.com\/#\/schema\/person\/1296fd7575f681c85a3afc18bf973b0c\"},\"description\":\"Learn how to use Profiler.BeginSample in Unity3D to optimize code performance by tracking and analyzing specific code segments. Improve game performance by identifying bottlenecks and optimizing execution time with these easy steps.\",\"breadcrumb\":{\"@id\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#primaryimage\",\"url\":\"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png\",\"contentUrl\":\"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/unity3dperformance.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use Profiler.BeginSample in Unity3D for Code Optimization\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/unity3dperformance.com\/#website\",\"url\":\"https:\/\/unity3dperformance.com\/\",\"name\":\"Unity3D Performance Blog\",\"description\":\"Discover tips and techniques to optimize your Unity3D projects for better performance and efficiency.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/unity3dperformance.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/unity3dperformance.com\/#\/schema\/person\/1296fd7575f681c85a3afc18bf973b0c\",\"name\":\"Rufi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/unity3dperformance.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3f1f6db23df2ef8fe5ff6875fbab10a67f1fcfef48afa45d5c00ed04d0ccf792?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3f1f6db23df2ef8fe5ff6875fbab10a67f1fcfef48afa45d5c00ed04d0ccf792?s=96&d=mm&r=g\",\"caption\":\"Rufi\"},\"sameAs\":[\"http:\/\/unity3dperformance.com\"],\"url\":\"https:\/\/unity3dperformance.com\/index.php\/author\/admin2826\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools - Unity3D Performance Blog","description":"Learn how to use Profiler.BeginSample in Unity3D to optimize code performance by tracking and analyzing specific code segments. Improve game performance by identifying bottlenecks and optimizing execution time with these easy steps.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/","og_locale":"en_US","og_type":"article","og_title":"How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools - Unity3D Performance Blog","og_description":"Learn how to use Profiler.BeginSample in Unity3D to optimize code performance by tracking and analyzing specific code segments. Improve game performance by identifying bottlenecks and optimizing execution time with these easy steps.","og_url":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/","og_site_name":"Unity3D Performance Blog","article_published_time":"2024-09-29T12:00:00+00:00","article_modified_time":"2024-09-29T18:17:19+00:00","og_image":[{"url":"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png"}],"author":"Rufi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rufi","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/","url":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/","name":"How to Use Profiler.BeginSample in Unity3D \u2013 Optimization with Profiling Tools - Unity3D Performance Blog","isPartOf":{"@id":"https:\/\/unity3dperformance.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#primaryimage"},"image":{"@id":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#primaryimage"},"thumbnailUrl":"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png","datePublished":"2024-09-29T12:00:00+00:00","dateModified":"2024-09-29T18:17:19+00:00","author":{"@id":"https:\/\/unity3dperformance.com\/#\/schema\/person\/1296fd7575f681c85a3afc18bf973b0c"},"description":"Learn how to use Profiler.BeginSample in Unity3D to optimize code performance by tracking and analyzing specific code segments. Improve game performance by identifying bottlenecks and optimizing execution time with these easy steps.","breadcrumb":{"@id":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#primaryimage","url":"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png","contentUrl":"https:\/\/unity3dperformance.com\/wp-content\/uploads\/2024\/09\/obraz-13-1024x536.png"},{"@type":"BreadcrumbList","@id":"https:\/\/unity3dperformance.com\/index.php\/2024\/09\/29\/profiler-beginsample-unity3d-optimization\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/unity3dperformance.com\/"},{"@type":"ListItem","position":2,"name":"How to Use Profiler.BeginSample in Unity3D for Code Optimization"}]},{"@type":"WebSite","@id":"https:\/\/unity3dperformance.com\/#website","url":"https:\/\/unity3dperformance.com\/","name":"Unity3D Performance Blog","description":"Discover tips and techniques to optimize your Unity3D projects for better performance and efficiency.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/unity3dperformance.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/unity3dperformance.com\/#\/schema\/person\/1296fd7575f681c85a3afc18bf973b0c","name":"Rufi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/unity3dperformance.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3f1f6db23df2ef8fe5ff6875fbab10a67f1fcfef48afa45d5c00ed04d0ccf792?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f1f6db23df2ef8fe5ff6875fbab10a67f1fcfef48afa45d5c00ed04d0ccf792?s=96&d=mm&r=g","caption":"Rufi"},"sameAs":["http:\/\/unity3dperformance.com"],"url":"https:\/\/unity3dperformance.com\/index.php\/author\/admin2826\/"}]}},"_links":{"self":[{"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":23,"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unity3dperformance.com\/index.php\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}