コード例 #1
0
 private CbVal(CbType tag, string str)
 {
     Type     = tag;
     data     = default;
     this.str = str;
     arr      = null;
     obj      = null;
     union    = null;
     numCache = null;
 }
コード例 #2
0
 private CbVal(CbType tag)
 {
     Type     = tag;
     data     = default;
     str      = null;
     arr      = null;
     obj      = null;
     union    = null;
     numCache = null;
 }
コード例 #3
0
 private CbVal(CbUnion union)
 {
     Type       = CbType.Union;
     data       = default;
     str        = null;
     arr        = null;
     obj        = null;
     this.union = union;
     numCache   = null;
 }
コード例 #4
0
 private CbVal(Dictionary <string, CbVal> obj)
 {
     Type     = CbType.Obj;
     data     = default;
     str      = null;
     arr      = null;
     this.obj = obj;
     union    = null;
     numCache = null;
 }
コード例 #5
0
 private CbVal(List <CbVal> arr)
 {
     Type     = CbType.Arr;
     data     = default;
     str      = null;
     this.arr = arr;
     obj      = null;
     union    = null;
     numCache = null;
 }
コード例 #6
0
 private CbVal(Guid uuid)
 {
     Type = CbType.UUID;
     data = new UnionStruct {
         uuid = uuid
     };
     str      = null;
     arr      = null;
     obj      = null;
     union    = null;
     numCache = null;
 }
コード例 #7
0
 private CbVal(DateTime date)
 {
     Type = CbType.Date;
     data = new UnionStruct {
         date = date
     };
     str      = null;
     arr      = null;
     obj      = null;
     union    = null;
     numCache = null;
 }
コード例 #8
0
 private CbVal(bool boolean)
 {
     Type = CbType.Bool;
     data = new UnionStruct {
         boolean = boolean
     };
     str      = null;
     arr      = null;
     obj      = null;
     union    = null;
     numCache = null;
 }
コード例 #9
0
ファイル: BitConverters.cs プロジェクト: dmitry-ra/benchmarks
        public void Execute(string[] args)
        {
            Options options = new Options();
            Parser.Default.ParseArguments(args, options);

            long loops = options.MegaLoops * 1000000L;
            int intsCount = options.IntsCount;

            Random random = new Random((int)DateTime.UtcNow.Ticks);
            Console.WriteLine($"UseVerification: {options.UseVerification}");
            if (options.UseVerification)
                Verification(random, intsCount);

            int[] ints = new int[intsCount];
            byte[] bytes = new byte[intsCount * 4];
            random.NextBytes(bytes);

            string type = options.ConverterType.ToLower();
            switch (type)
            {
                case BitConverterTestName:
                    for (long i = 0; i < loops; i++)
                    {
                        BitConverterProcess(bytes, ints);
                    }
                    break;

                case ConversionStructTestName:
                    for (long i = 0; i < loops; i++)
                    {
                        ConversionStructProcess(bytes, ints);
                    }
                    break;

                case BlockCopyTestName:
                    for (long i = 0; i < loops; i++)
                    {
                        BlockCopyProcess(bytes, ints);
                    }
                    break;

                case UnionStructTestName:
                    for (long i = 0; i < loops; i++)
                    {
                        UnionStructProcess(bytes, ints);
                    }
                    break;

                case ManualTestName:
                    for (long i = 0; i < loops; i++)
                    {
                        ManualProcess(bytes, ints);
                    }
                    break;

                case GetBytesUnionStructTestName:
                    BlockCopyProcess(bytes, ints);
                    int x1 = ints[0];
                    var p = Marshal.AllocHGlobal(4);
                    for (long i = 0; i < loops; i++)
                    {
                        bytes = new byte[4];
                        UnionStruct us = new UnionStruct();
                        us.Int32 = x1;
                        bytes[0] = us.Byte_0;
                        bytes[1] = us.Byte_1;
                        bytes[2] = us.Byte_2;
                        bytes[3] = us.Byte_3;
                    }
                    Marshal.FreeHGlobal(p);
                    break;

                case GetBytesBitConverterTestName:
                    BlockCopyProcess(bytes, ints);
                    int x2 = ints[0];
                    for (long i = 0; i < loops; i++)
                    {
                        bytes = BitConverter.GetBytes(x2);
                    }
                    break;

                case GetBytesManualTestName:
                    BlockCopyProcess(bytes, ints);
                    int x3 = ints[0];
                    for (long i = 0; i < loops; i++)
                    {
                        bytes = new byte[4];
                        bytes[0] = (byte)x3;
                        bytes[1] = (byte)(x3 >> 8);
                        bytes[2] = (byte)(x3 >> 16);
                        bytes[3] = (byte)(x3 >> 24);
                    }
                    break;

                default:
                    throw new Exception($"Unknown type '{type}'");
            }
        }
コード例 #10
0
ファイル: BitConverters.cs プロジェクト: dmitry-ra/benchmarks
 private void UnionStructProcess(byte[] bytes, int[] ints)
 {
     var us = new UnionStruct();
     var i = 0;
     var j = 0;
     var count = bytes.Length;
     while (i < count)
     {
         us.Byte_0 = bytes[i++];
         us.Byte_1 = bytes[i++];
         us.Byte_2 = bytes[i++];
         us.Byte_3 = bytes[i++];
         ints[j++] = us.Int32;
     }
 }
コード例 #11
0
 ComplexStruct IFoo.MethodForStruct(ref UnionStruct p1, out InteropDeleWithStructArray p2) { p2 = null; return new ComplexStruct(); }