Beispiel #1
0
        static void ProfileBitMath()
        {
            byte    b1, br; b1 = 0x18;
            sbyte   sb1, sbr; sb1 = 0x18;
            ushort  us1, usr; us1 = 0x1ff8;
            short   s1, sr; s1 = 0x1ff8;
            uint    ui1, uir; ui1 = 0x1ffffff8;
            int     i1, ir; i1 = 0x1ffffff8;
            ulong   ul1, ulr; ul1 = 0x1ffffffffffffff8;
            long    l1, lr; l1 = 0x1ffffffffffffff8;
            UInt128 ull1, ullr; ull1 = new UInt128(0x1fffffffffffffff, 0xfffffffffffffff8);
            var     bench = new Bench();

            bench.Time("byte.LowBit", () => { br = b1.LowBit(); br = b1.LowBit(); br = b1.LowBit(); br = b1.LowBit(); br = b1.LowBit(); }, 5);
            bench.Time("sbyte.LowBit", () => { sbr = sb1.LowBit(); sbr = sb1.LowBit(); sbr = sb1.LowBit(); sbr = sb1.LowBit(); sbr = sb1.LowBit(); }, 5);
            bench.Time("ushort.LowBit", () => { usr = us1.LowBit(); usr = us1.LowBit(); usr = us1.LowBit(); usr = us1.LowBit(); usr = us1.LowBit(); }, 5);
            bench.Time("short.LowBit", () => { sr = s1.LowBit(); sr = s1.LowBit(); sr = s1.LowBit(); sr = s1.LowBit(); sr = s1.LowBit(); }, 5);
            bench.Time("uint.LowBit", () => { uir = ui1.LowBit(); uir = ui1.LowBit(); uir = ui1.LowBit(); uir = ui1.LowBit(); uir = ui1.LowBit(); }, 5);
            bench.Time("int.LowBit", () => { ir = i1.LowBit(); ir = i1.LowBit(); ir = i1.LowBit(); ir = i1.LowBit(); ir = i1.LowBit(); }, 5);
            bench.Time("ulong.LowBit", () => { ulr = ul1.LowBit(); ulr = ul1.LowBit(); ulr = ul1.LowBit(); ulr = ul1.LowBit(); ulr = ul1.LowBit(); }, 5);
            bench.Time("long.LowBit", () => { lr = l1.LowBit(); lr = l1.LowBit(); lr = l1.LowBit(); lr = l1.LowBit(); lr = l1.LowBit(); }, 5);
            bench.Time("UInt128.LowBit", () => { ullr = ull1.LowBit(); ullr = ull1.LowBit(); ullr = ull1.LowBit(); ullr = ull1.LowBit(); ullr = ull1.LowBit(); }, 5);
            bench.Time("byte.HighBit", () => { br = b1.HighBit(); br = b1.HighBit(); br = b1.HighBit(); br = b1.HighBit(); br = b1.HighBit(); }, 5);
            bench.Time("sbyte.HighBit", () => { sbr = sb1.HighBit(); sbr = sb1.HighBit(); sbr = sb1.HighBit(); sbr = sb1.HighBit(); sbr = sb1.HighBit(); }, 5);
            bench.Time("ushort.HighBit", () => { usr = us1.HighBit(); usr = us1.HighBit(); usr = us1.HighBit(); usr = us1.HighBit(); usr = us1.HighBit(); }, 5);
            bench.Time("short.HighBit", () => { sr = s1.HighBit(); sr = s1.HighBit(); sr = s1.HighBit(); sr = s1.HighBit(); sr = s1.HighBit(); }, 5);
            bench.Time("uint.HighBit", () => { uir = ui1.HighBit(); uir = ui1.HighBit(); uir = ui1.HighBit(); uir = ui1.HighBit(); uir = ui1.HighBit(); }, 5);
            bench.Time("int.HighBit", () => { ir = i1.HighBit(); ir = i1.HighBit(); ir = i1.HighBit(); ir = i1.HighBit(); ir = i1.HighBit(); }, 5);
            bench.Time("ulong.HighBit", () => { ulr = ul1.HighBit(); ulr = ul1.HighBit(); ulr = ul1.HighBit(); ulr = ul1.HighBit(); ulr = ul1.HighBit(); }, 5);
            bench.Time("long.HighBit", () => { lr = l1.HighBit(); lr = l1.HighBit(); lr = l1.HighBit(); lr = l1.HighBit(); lr = l1.HighBit(); }, 5);
            bench.Time("UInt128.HighBit", () => { ullr = ull1.HighBit(); ullr = ull1.HighBit(); ullr = ull1.HighBit(); ullr = ull1.HighBit(); ullr = ull1.HighBit(); }, 5);
            bench.Time("byte.LowBitPosition", () => { ir = b1.LowBitPosition(); ir = b1.LowBitPosition(); ir = b1.LowBitPosition(); ir = b1.LowBitPosition(); ir = b1.LowBitPosition(); }, 5);
            bench.Time("sbyte.LowBitPosition", () => { ir = sb1.LowBitPosition(); ir = sb1.LowBitPosition(); ir = sb1.LowBitPosition(); ir = sb1.LowBitPosition(); ir = sb1.LowBitPosition(); }, 5);
            bench.Time("ushort.LowBitPosition", () => { ir = us1.LowBitPosition(); ir = us1.LowBitPosition(); ir = us1.LowBitPosition(); ir = us1.LowBitPosition(); ir = us1.LowBitPosition(); }, 5);
            bench.Time("short.LowBitPosition", () => { ir = s1.LowBitPosition(); ir = s1.LowBitPosition(); ir = s1.LowBitPosition(); ir = s1.LowBitPosition(); ir = s1.LowBitPosition(); }, 5);
            bench.Time("uint.LowBitPosition", () => { ir = ui1.LowBitPosition(); ir = ui1.LowBitPosition(); ir = ui1.LowBitPosition(); ir = ui1.LowBitPosition(); ir = ui1.LowBitPosition(); }, 5);
            bench.Time("int.LowBitPosition", () => { ir = i1.LowBitPosition(); ir = i1.LowBitPosition(); ir = i1.LowBitPosition(); ir = i1.LowBitPosition(); ir = i1.LowBitPosition(); }, 5);
            bench.Time("ulong.LowBitPosition", () => { ir = ul1.LowBitPosition(); ir = ul1.LowBitPosition(); ir = ul1.LowBitPosition(); ir = ul1.LowBitPosition(); ir = ul1.LowBitPosition(); }, 5);
            bench.Time("long.LowBitPosition", () => { ir = l1.LowBitPosition(); ir = l1.LowBitPosition(); ir = l1.LowBitPosition(); ir = l1.LowBitPosition(); ir = l1.LowBitPosition(); }, 5);
            bench.Time("UInt128.LowBitPosition", () => { ir = ull1.LowBitPosition(); ir = ull1.LowBitPosition(); ir = ull1.LowBitPosition(); ir = ull1.LowBitPosition(); ir = ull1.LowBitPosition(); }, 5);
            bench.Time("byte.HighBitPosition", () => { ir = b1.HighBitPosition(); ir = b1.HighBitPosition(); ir = b1.HighBitPosition(); ir = b1.HighBitPosition(); ir = b1.HighBitPosition(); }, 5);
            bench.Time("sbyte.HighBitPosition", () => { ir = sb1.HighBitPosition(); ir = sb1.HighBitPosition(); ir = sb1.HighBitPosition(); ir = sb1.HighBitPosition(); ir = sb1.HighBitPosition(); }, 5);
            bench.Time("ushort.HighBitPosition", () => { ir = us1.HighBitPosition(); ir = us1.HighBitPosition(); ir = us1.HighBitPosition(); ir = us1.HighBitPosition(); ir = us1.HighBitPosition(); }, 5);
            bench.Time("short.HighBitPosition", () => { ir = s1.HighBitPosition(); ir = s1.HighBitPosition(); ir = s1.HighBitPosition(); ir = s1.HighBitPosition(); ir = s1.HighBitPosition(); }, 5);
            bench.Time("uint.HighBitPosition", () => { ir = ui1.HighBitPosition(); ir = ui1.HighBitPosition(); ir = ui1.HighBitPosition(); ir = ui1.HighBitPosition(); ir = ui1.HighBitPosition(); }, 5);
            bench.Time("int.HighBitPosition", () => { ir = i1.HighBitPosition(); ir = i1.HighBitPosition(); ir = i1.HighBitPosition(); ir = i1.HighBitPosition(); ir = i1.HighBitPosition(); }, 5);
            bench.Time("ulong.HighBitPosition", () => { ir = ul1.HighBitPosition(); ir = ul1.HighBitPosition(); ir = ul1.HighBitPosition(); ir = ul1.HighBitPosition(); ir = ul1.HighBitPosition(); }, 5);
            bench.Time("long.HighBitPosition", () => { ir = l1.HighBitPosition(); ir = l1.HighBitPosition(); ir = l1.HighBitPosition(); ir = l1.HighBitPosition(); ir = l1.HighBitPosition(); }, 5);
            bench.Time("UInt128.HighBitPosition", () => { ir = ull1.HighBitPosition(); ir = ull1.HighBitPosition(); ir = ull1.HighBitPosition(); ir = ull1.HighBitPosition(); ir = ull1.HighBitPosition(); }, 5);
            bench.Time("byte.TrailingZeroBits", () => { ir = b1.TrailingZeroBits(); ir = b1.TrailingZeroBits(); ir = b1.TrailingZeroBits(); ir = b1.TrailingZeroBits(); ir = b1.TrailingZeroBits(); }, 5);
            bench.Time("sbyte.TrailingZeroBits", () => { ir = sb1.TrailingZeroBits(); ir = sb1.TrailingZeroBits(); ir = sb1.TrailingZeroBits(); ir = sb1.TrailingZeroBits(); ir = sb1.TrailingZeroBits(); }, 5);
            bench.Time("ushort.TrailingZeroBits", () => { ir = us1.TrailingZeroBits(); ir = us1.TrailingZeroBits(); ir = us1.TrailingZeroBits(); ir = us1.TrailingZeroBits(); ir = us1.TrailingZeroBits(); }, 5);
            bench.Time("short.TrailingZeroBits", () => { ir = s1.TrailingZeroBits(); ir = s1.TrailingZeroBits(); ir = s1.TrailingZeroBits(); ir = s1.TrailingZeroBits(); ir = s1.TrailingZeroBits(); }, 5);
            bench.Time("uint.TrailingZeroBits", () => { ir = ui1.TrailingZeroBits(); ir = ui1.TrailingZeroBits(); ir = ui1.TrailingZeroBits(); ir = ui1.TrailingZeroBits(); ir = ui1.TrailingZeroBits(); }, 5);
            bench.Time("int.TrailingZeroBits", () => { ir = i1.TrailingZeroBits(); ir = i1.TrailingZeroBits(); ir = i1.TrailingZeroBits(); ir = i1.TrailingZeroBits(); ir = i1.TrailingZeroBits(); }, 5);
            bench.Time("ulong.TrailingZeroBits", () => { ir = ul1.TrailingZeroBits(); ir = ul1.TrailingZeroBits(); ir = ul1.TrailingZeroBits(); ir = ul1.TrailingZeroBits(); ir = ul1.TrailingZeroBits(); }, 5);
            bench.Time("long.TrailingZeroBits", () => { ir = l1.TrailingZeroBits(); ir = l1.TrailingZeroBits(); ir = l1.TrailingZeroBits(); ir = l1.TrailingZeroBits(); ir = l1.TrailingZeroBits(); }, 5);
            bench.Time("UInt128.TrailingZeroBits", () => { ir = ull1.TrailingZeroBits(); ir = ull1.TrailingZeroBits(); ir = ull1.TrailingZeroBits(); ir = ull1.TrailingZeroBits(); ir = ull1.TrailingZeroBits(); }, 5);
            bench.Time("byte.LeadingZeroBits", () => { ir = b1.LeadingZeroBits(); ir = b1.LeadingZeroBits(); ir = b1.LeadingZeroBits(); ir = b1.LeadingZeroBits(); ir = b1.LeadingZeroBits(); }, 5);
            bench.Time("sbyte.LeadingZeroBits", () => { ir = sb1.LeadingZeroBits(); ir = sb1.LeadingZeroBits(); ir = sb1.LeadingZeroBits(); ir = sb1.LeadingZeroBits(); ir = sb1.LeadingZeroBits(); }, 5);
            bench.Time("ushort.LeadingZeroBits", () => { ir = us1.LeadingZeroBits(); ir = us1.LeadingZeroBits(); ir = us1.LeadingZeroBits(); ir = us1.LeadingZeroBits(); ir = us1.LeadingZeroBits(); }, 5);
            bench.Time("short.LeadingZeroBits", () => { ir = s1.LeadingZeroBits(); ir = s1.LeadingZeroBits(); ir = s1.LeadingZeroBits(); ir = s1.LeadingZeroBits(); ir = s1.LeadingZeroBits(); }, 5);
            bench.Time("uint.LeadingZeroBits", () => { ir = ui1.LeadingZeroBits(); ir = ui1.LeadingZeroBits(); ir = ui1.LeadingZeroBits(); ir = ui1.LeadingZeroBits(); ir = ui1.LeadingZeroBits(); }, 5);
            bench.Time("int.LeadingZeroBits", () => { ir = i1.LeadingZeroBits(); ir = i1.LeadingZeroBits(); ir = i1.LeadingZeroBits(); ir = i1.LeadingZeroBits(); ir = i1.LeadingZeroBits(); }, 5);
            bench.Time("ulong.LeadingZeroBits", () => { ir = ul1.LeadingZeroBits(); ir = ul1.LeadingZeroBits(); ir = ul1.LeadingZeroBits(); ir = ul1.LeadingZeroBits(); ir = ul1.LeadingZeroBits(); }, 5);
            bench.Time("long.LeadingZeroBits", () => { ir = l1.LeadingZeroBits(); ir = l1.LeadingZeroBits(); ir = l1.LeadingZeroBits(); ir = l1.LeadingZeroBits(); ir = l1.LeadingZeroBits(); }, 5);
            bench.Time("UInt128.LeadingZeroBits", () => { ir = ull1.LeadingZeroBits(); ir = ull1.LeadingZeroBits(); ir = ull1.LeadingZeroBits(); ir = ull1.LeadingZeroBits(); ir = ull1.LeadingZeroBits(); }, 5);
            bench.Time("byte.BitCount", () => { ir = b1.BitCount(); ir = b1.BitCount(); ir = b1.BitCount(); ir = b1.BitCount(); ir = b1.BitCount(); }, 5);
            bench.Time("sbyte.BitCount", () => { ir = sb1.BitCount(); ir = sb1.BitCount(); ir = sb1.BitCount(); ir = sb1.BitCount(); ir = sb1.BitCount(); }, 5);
            bench.Time("ushort.BitCount", () => { ir = us1.BitCount(); ir = us1.BitCount(); ir = us1.BitCount(); ir = us1.BitCount(); ir = us1.BitCount(); }, 5);
            bench.Time("short.BitCount", () => { ir = s1.BitCount(); ir = s1.BitCount(); ir = s1.BitCount(); ir = s1.BitCount(); ir = s1.BitCount(); }, 5);
            bench.Time("uint.BitCount", () => { ir = ui1.BitCount(); ir = ui1.BitCount(); ir = ui1.BitCount(); ir = ui1.BitCount(); ir = ui1.BitCount(); }, 5);
            bench.Time("int.BitCount", () => { ir = i1.BitCount(); ir = i1.BitCount(); ir = i1.BitCount(); ir = i1.BitCount(); ir = i1.BitCount(); }, 5);
            bench.Time("ulong.BitCount", () => { ir = ul1.BitCount(); ir = ul1.BitCount(); ir = ul1.BitCount(); ir = ul1.BitCount(); ir = ul1.BitCount(); }, 5);
            bench.Time("long.BitCount", () => { ir = l1.BitCount(); ir = l1.BitCount(); ir = l1.BitCount(); ir = l1.BitCount(); ir = l1.BitCount(); }, 5);
            bench.Time("UInt128.BitCount", () => { ir = ull1.BitCount(); ir = ull1.BitCount(); ir = ull1.BitCount(); ir = ull1.BitCount(); ir = ull1.BitCount(); }, 5);
            bench.Time("byte.ReverseBits", () => { br = b1.ReverseBits(); br = b1.ReverseBits(); br = b1.ReverseBits(); br = b1.ReverseBits(); br = b1.ReverseBits(); }, 5);
            bench.Time("sbyte.ReverseBits", () => { sbr = sb1.ReverseBits(); sbr = sb1.ReverseBits(); sbr = sb1.ReverseBits(); sbr = sb1.ReverseBits(); sbr = sb1.ReverseBits(); }, 5);
            bench.Time("ushort.ReverseBits", () => { usr = us1.ReverseBits(); usr = us1.ReverseBits(); usr = us1.ReverseBits(); usr = us1.ReverseBits(); usr = us1.ReverseBits(); }, 5);
            bench.Time("short.ReverseBits", () => { sr = s1.ReverseBits(); sr = s1.ReverseBits(); sr = s1.ReverseBits(); sr = s1.ReverseBits(); sr = s1.ReverseBits(); }, 5);
            bench.Time("uint.ReverseBits", () => { uir = ui1.ReverseBits(); uir = ui1.ReverseBits(); uir = ui1.ReverseBits(); uir = ui1.ReverseBits(); uir = ui1.ReverseBits(); }, 5);
            bench.Time("int.ReverseBits", () => { ir = i1.ReverseBits(); ir = i1.ReverseBits(); ir = i1.ReverseBits(); ir = i1.ReverseBits(); ir = i1.ReverseBits(); }, 5);
            bench.Time("ulong.ReverseBits", () => { ulr = ul1.ReverseBits(); ulr = ul1.ReverseBits(); ulr = ul1.ReverseBits(); ulr = ul1.ReverseBits(); ulr = ul1.ReverseBits(); }, 5);
            bench.Time("long.ReverseBits", () => { lr = l1.ReverseBits(); lr = l1.ReverseBits(); lr = l1.ReverseBits(); lr = l1.ReverseBits(); lr = l1.ReverseBits(); }, 5);
            bench.Time("UInt128.ReverseBits", () => { ullr = ull1.ReverseBits(); ullr = ull1.ReverseBits(); ullr = ull1.ReverseBits(); ullr = ull1.ReverseBits(); ullr = ull1.ReverseBits(); }, 5);
        }