C# Int32型とInt64型の演算処理のパフォーマンスについて

Int32型とInt64型の演算処理のパフォーマンスを計測する

計測用のコードは、以下の通り

//Int32型の演算処理のパフォーマンスを計測する
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = Stopwatch.StartNew();
        for (Int32 i = 0; i < Int32.MaxValue; i++)
        {
            Int32 i32 = 1;
            i32 += 1;
        }
        Console.WriteLine("Int32型の演算:{0}", stopWatch.Elapsed);
    }
}

  • 実行結果
  • Int32型の演算:00:00:04.3882120



    //Int64型の演算処理のパフォーマンスを計測する
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Diagnostics;
    
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();
            for (Int32 i = 0; i < Int32.MaxValue; i++)
            {
                Int64 i64 = 1;
                i64 += 1;
            }
            Console.WriteLine("Int64型の演算:{0}", stopWatch.Elapsed);
        }
    }


  • 実行結果
  • Int64型の演算:00:00:07.6880102




  • 実行環境

  • OSWindows Vista Home Premium(32bit)
    開発環境Visual Studio 2005 Standard
    CPUIntel Core2 Quad 2.66GHz
    メモリ4GB




  • 結果

  • Int32型オブジェクトの処理のほうがInt64型オブジェクトの処理よりも約1.7倍速い