using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace ConsoleApplication1 { /* * 179 * 180 * 178 * 210 * 275 * 180 * 187 * 195 * 183 * 198 * 平均=196.5 */ class Program { static void Main(string[] args) { foo a = new foo(); Stopwatch sw = new Stopwatch(); sw.Start(); a.start(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); } } class foo { int value = 0; public void start() { for (long i = 0; i < 1000000; i++) { AddToBitfield(ref value, 5, 31); AddToBitfield(ref value, 5, 31); AddToBitfield(ref value, 5, 31); AddToBitfield(ref value, 5, 31); AddToBitfield(ref value, 5, 31); AddToBitfield(ref value, 5, 31); ReadFromBitfield(ref value, 5); ReadFromBitfield(ref value, 5); ReadFromBitfield(ref value, 5); ReadFromBitfield(ref value, 5); ReadFromBitfield(ref value, 5); } } void AddToBitfield(ref int a, int bitCount, int value) { a *= bitCount; a += value; } int ReadFromBitfield(ref int a, int bitCount) { int value = a / bitCount; a -= value; return value; } } }