LoginSignup
18
13

More than 5 years have passed since last update.

【Unity】一度読み込んだリソースをキャッシュする場合としない場合で読み込み速度にどれくらい差が出るか検証しました

Last updated at Posted at 2016-01-18

■2016/1/18 18:30 追記
最後の表の「キャッシュしない場合」「キャッシュする場合」が逆になっていたため修正しました


Resources.Loadでリソースを読み込む際に
一度読み込んだリソースをキャッシュするかしないかで
どれくらい速度に差が出るか気になったので検証しました

検証環境

  • Unity:5.3.1f1
  • OS:Android
  • モデル番号:Nexus 7
  • Androidバージョン:5.0.1

検証に使用するリソース

1024x1024のテクスチャ

読み込む方法

キャッシュしない場合

キャッシュしない場合はResources.Loadを直接使用します

Resources.Load<Texture>( "image" );

キャッシュする場合

キャッシュする場合は下記のようなラッパークラスを作成して使用します

using UnityEngine;
using System.Collections.Generic;

public static class Loader
{
    private static readonly Dictionary<string, Texture> mList = new Dictionary<string, Texture>();

    public static Texture Load( string path )
    {
        if ( !mList.ContainsKey( path ) )
        {
            mList[ path ] = Resources.Load<Texture>( path );
        }
        return mList[ path ];
    }

    public static void Clear()
    {
        mList.Clear();
    }
}
Loader.Load( "image" );

読み込み時間(秒)の比較

形式 1,000件 10,000件 100,000件
キャッシュしない場合 0.0139160200 0.135650600 1.34741200
キャッシュする場合 0.0009155273 0.007965088 0.08035278

検証用のスクリプト

https://gist.github.com/baba-s/957f7f549d5852e2bc12
https://gist.github.com/baba-s/53e486f3832268f56953

18
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
13