BeginSample() private method

private BeginSample ( string name ) : void
name string
return void
    static PackedMemorySnapshot LoadFromFile(string filePath)
    {
        Debug.LogFormat("Loading...");
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        PackedMemorySnapshot         result;
        string fileExtension = Path.GetExtension(filePath);

        if (string.Equals(fileExtension, ".memsnap3", System.StringComparison.OrdinalIgnoreCase))
        {
            Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(litjson)");
            stopwatch.Start();

            using (TextReader reader = File.OpenText(filePath)) {
                var errors     = new List <string>();
                var serializer = getSerializer(errors);
                result = (PackedMemorySnapshot)serializer.Deserialize(reader, typeof(PackedMemorySnapshot));
                logErrors(errors);
            }

            stopwatch.Stop();
            Profiler.EndSample();
        }
        else if (string.Equals(fileExtension, ".memsnap2", System.StringComparison.OrdinalIgnoreCase))
        {
            Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(json)");
            stopwatch.Start();

            var json = File.ReadAllText(filePath);
            result = JsonUtility.FromJson <PackedMemorySnapshot>(json);

            stopwatch.Stop();
            Profiler.EndSample();
        }
        else if (string.Equals(fileExtension, ".memsnap", System.StringComparison.OrdinalIgnoreCase))
        {
            Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(binary)");
            stopwatch.Start();

            var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            using (Stream stream = File.Open(filePath, FileMode.Open))
            {
                result = binaryFormatter.Deserialize(stream) as PackedMemorySnapshot;
            }

            stopwatch.Stop();
            Profiler.EndSample();
        }
        else
        {
            Debug.LogErrorFormat("MemoryProfiler: Unrecognized memory snapshot format '{0}'.", filePath);
            result = null;
        }

        Debug.LogFormat("Loading took {0}ms", stopwatch.ElapsedMilliseconds);
        return(result);
    }
    static void SaveToFile(string filePath, PackedMemorySnapshot snapshot)
    {
        // Saving snapshots using JsonUtility, instead of BinaryFormatter, is significantly faster.
        // I cancelled saving a memory snapshot that is saving using BinaryFormatter after 24 hours.
        // Saving the same memory snapshot using JsonUtility.ToJson took 20 seconds only.

        Debug.LogFormat("Saving...");
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        Profiler.BeginSample("PackedMemorySnapshotUtility.SaveToFile");
        stopwatch.Start();

        string fileExtension = Path.GetExtension(filePath);

        if (string.Equals(fileExtension, ".memsnap", System.StringComparison.OrdinalIgnoreCase))
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            using (Stream stream = File.Open(filePath, FileMode.Create)) {
                bf.Serialize(stream, snapshot);
            }
        }
        else if (string.Equals(fileExtension, ".memsnap2", System.StringComparison.OrdinalIgnoreCase))
        {
            var json = JsonUtility.ToJson(snapshot);
            File.WriteAllText(filePath, json);
        }
        else     // memsnap3 + default
        // Stream writing -- will not to exhaust memory (for large snapshots)
        {
            using (TextWriter writer = File.CreateText(filePath)) {
                var errors     = new List <string>();
                var serializer = getSerializer(errors);
                serializer.Serialize(writer, snapshot);
                logErrors(errors);
            }
        }

        stopwatch.Stop();
        Profiler.EndSample();
        Debug.LogFormat("Saving took {0}ms", stopwatch.ElapsedMilliseconds);
    }