Esempio n. 1
0
        static async Task Main(string[] args)
        {
            if (MemoryProfiler.IsActive)
            {
                MemoryProfiler.EnableAllocations();
            }

            bool managed = false;

            Environment.SetEnvironmentVariable("System.Data.SqlClient.UseManagedSNIOnWindows", managed.ToString());
            await Task.CompletedTask;

            if (args != null && args.Length > 0)
            {
                BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
                Console.ReadLine();
            }
            else
            {
                Stopwatch timer = new Stopwatch();



                var bench = new WriteBenchmarks();
                bench.GlobalSetup();
                timer.Start();

                if (MemoryProfiler.IsActive)
                {
                    MemoryProfiler.Dump();
                }

                for (int index = 0; index < 100; index++)
                {
                    //bench.IterationSetup();

                    //bench.SyncFloat32();

                    //bench.ReadOrderDetails();

                    bench.SyncGuid();

                    //await bench.AsyncFloat32();

                    //bench.ChangeType();

                    //bench.OpenClose();
                }

                if (MemoryProfiler.IsActive)
                {
                    MemoryProfiler.Dump();
                }

                timer.Stop();
                bench.GlobalCleanup();



                Console.WriteLine(timer.Elapsed);
            }
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            if (MemoryProfiler.IsActive)
            {
                MemoryProfiler.EnableAllocations();
            }

            bool managed = false;

            Environment.SetEnvironmentVariable("System.Data.SqlClient.UseManagedSNIOnWindows", managed.ToString());
            Environment.SetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1");
            await Task.CompletedTask;

            //if (args != null && args.Length > 0)
            //{
            //	BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
            //	Console.ReadLine();
            //}
            //else
            {
                Stopwatch timer = new Stopwatch();



                var bench = new WriteBenchmarks();
                bench.GlobalSetup();


                //var param = new SqlParameter("@value", System.Data.SqlDbType.Float); //new SqlParameter("@value", System.Data.SqlDbType.Float, 4);//bench.syncFloat32parameter;
                //var internalField = param.GetType().GetField("_metaType", BindingFlags.NonPublic | BindingFlags.Instance);
                //var internalMetaTypeBefore = internalField.GetValue(param);
                //param.Value = (float)1.1;
                ////bench.syncFloat32command.ExecuteNonQuery();
                //var internalMetaTypeAfter = internalField.GetValue(param);


                //var metaTypeType = typeof(SqlCommand).Assembly.GetType("System.Data.SqlClient.MetaType");
                //var getMetaTypeFromValue = metaTypeType.GetMethod(
                //	"GetMetaTypeFromValue",
                //	0,
                //	BindingFlags.Static | BindingFlags.NonPublic,
                //	null,
                //	CallingConventions.Standard,
                //	new Type[] { typeof(Type),typeof(object),typeof(bool),typeof(bool) },
                //	null
                //);
                //var calculateMetaType = getMetaTypeFromValue.Invoke(null, new object[] { typeof(float),null,false,false});


                //var internalMetaType = internalField.GetValue(param);

                //var validate = param.GetType().GetMethod("GetMetaTypeOnly", BindingFlags.NonPublic | BindingFlags.Instance);
                //object metaType = validate.Invoke(param, null);

                ////var method = param.GetType().GetMethod("GetCoercedValue", BindingFlags.Instance | BindingFlags.NonPublic);
                ////object directValue = param.Value;
                ////object coercedValue = method.Invoke(param, BindingFlags.Instance | BindingFlags.NonPublic|BindingFlags.InvokeMethod,null,null, System.Globalization.CultureInfo.CurrentCulture);



                timer.Start();

                if (MemoryProfiler.IsActive)
                {
                    MemoryProfiler.Dump();
                }

                for (int index = 0; index < 100; index++)
                {
                    //bench.IterationSetup();

                    //bench.SyncFloat32();

                    //bench.ReadOrderDetails();

                    bench.ReadStoredProc();

                    //bench.SyncGuid();

                    //await bench.AsyncFloat32();

                    //bench.ChangeType();

                    //bench.OpenClose();
                }

                if (MemoryProfiler.IsActive)
                {
                    MemoryProfiler.Dump();
                }

                timer.Stop();
                bench.GlobalCleanup();



                Console.WriteLine(timer.Elapsed);
                //if (!MemoryProfiler.IsActive)
                //{
                //	Console.ReadLine();
                //}
            }
        }