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
OS | Windows Vista Home Premium(32bit) |
開発環境 | Visual Studio 2005 Standard |
CPU | Intel Core2 Quad 2.66GHz |
メモリ | 4GB |
Int32型オブジェクトの処理のほうがInt64型オブジェクトの処理よりも約1.7倍速い