コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】gzip と brotli の圧縮・展開の比較

使用するクラス

検証用のクラス

using MyProject;
using Unity.Profiling;
using UnityEngine;

public sealed class Example : MonoBehaviour
{
    private void Start()
    {
        const int    count = 10000;
        const string text  = "ピカチュウ";

        var gzipCompressedBytes   = GZipCompressor.Compress( text );
        var brotliCompressedBytes = BrotliCompressor.Compress( text );

        using ( new ProfilerMarker( "1. gzip compress" ).Auto() )
        {
            for ( var i = 0; i < count; i++ )
            {
                GZipCompressor.Compress( text );
            }
        }

        using ( new ProfilerMarker( "2. gzip decompress" ).Auto() )
        {
            for ( var i = 0; i < count; i++ )
            {
                GZipCompressor.Decompress( gzipCompressedBytes );
            }
        }

        using ( new ProfilerMarker( "3. brotli compress" ).Auto() )
        {
            for ( var i = 0; i < count; i++ )
            {
                BrotliCompressor.Compress( text );
            }
        }

        using ( new ProfilerMarker( "4. brotli decompress" ).Auto() )
        {
            for ( var i = 0; i < count; i++ )
            {
                BrotliCompressor.Decompress( brotliCompressedBytes );
            }
        }
    }
}

検証結果