何となく速度確認


やはりクラス/構造体で全てをStringで保持するのは駄目だな。

string:628.0491
object:44.0045
int:19.0004
refInt:16.003
    DateTime start = DateTime.Now;

    for (int i = 0; i < 1000000; i++)
    {
      i = getInt(i.ToString());
    }//end loop

    Console.WriteLine("string:{0}", (DateTime.Now - start).TotalMilliseconds);
    start = DateTime.Now;

    for (int i = 0; i < 1000000; i++)
    {
      i = getInt((object)i);

    }//end loop

    Console.WriteLine("object:{0}", (DateTime.Now - start).TotalMilliseconds);
    start = DateTime.Now;

    for (int i = 0; i < 1000000; i++)
    {
      i = getInt(i);
    }//end loop

    Console.WriteLine("int:{0}", (DateTime.Now - start).TotalMilliseconds);
    start = DateTime.Now;

    for (int i = 0; i < 1000000; i++)
    {
      refInt(ref i);
      i = i;
    }
    Console.WriteLine("refInt:{0}", (DateTime.Now - start).TotalMilliseconds);
    start = DateTime.Now;

  }

  private static int getInt(object obj)
  {
    return Convert.ToInt32(obj);
  }

  private static int getInt(int a)
  {
    return a; 
  }

  private static int getInt(string str)
  {
    return Convert.ToInt32(str);
  }

  private static void refInt(ref int a)
  {
    a = a;
  }
カテゴリー: 開発 タグ: パーマリンク