Пример #1
0
        public void RunTests()
        {
            double dResult = 0;

            double[] matrix1 = new double[3 * 1024 * 1024];
            double[] matrix2 = new double[3 * 1024 * 1024];

            //  Run the tests through the pinvoke.
            stopwatch.Restart();
            for (ulong i = 1; i <= testCount; i++)
            {
                TA_IncrementCounter();
            }
            stopwatch.Stop();
            PInvoke_Test1_Time = Math.Round(stopwatch.Elapsed.TotalMilliseconds, 4);

            // Structure with a pointer to another structure.
            MyPerson personName = new MyPerson()
            {
                first = "Mark", last = "Lee"
            };
            MyPerson2 personAll = new MyPerson2()
            {
                age = 35, person = personName
            };

            stopwatch.Restart();
            for (ulong i = 1; i <= testCount; i++)
            {
                IntPtr buffer1 = Marshal.AllocCoTaskMem(Marshal.SizeOf(personAll));
                Marshal.StructureToPtr(personAll, buffer1, false);

                var res = PerformanceTestCore.TestStructInStruct(buffer1);
                DeleteObjectAPI(res);
                Marshal.FreeCoTaskMem(buffer1);
            }
            stopwatch.Stop();
            PInvoke_Test2_Time = Math.Round(stopwatch.Elapsed.TotalMilliseconds, 4);

            dResult = 0;
            stopwatch.Restart();
            for (ulong i = 1; i <= testCount; i++)
            {
                matrix1[0] = i;
                matrix1[1] = i;
                matrix1[2] = i;

                matrix2[0] = i;
                matrix2[1] = i;
                matrix2[2] = i;

                dResult += TA_DotProduct(matrix1, matrix2);
            }
            stopwatch.Stop();
            PInvoke_Test3_Time = Math.Round(stopwatch.Elapsed.TotalMilliseconds, 4);
        }
Пример #2
0
        void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //  Set the view model properties.
            PerformanceTestCore test = e.Result as PerformanceTestCore;

            PInvoke_Test1_Result = test.PInvoke_Test1_Time;
            PInvoke_Test2_Result = test.PInvoke_Test2_Time;
            PInvoke_Test3_Result = test.PInvoke_Test3_Time;

            //  We can now run the command again.
            runTestsCommand.CanExecute = true;
        }
Пример #3
0
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            //  Create a performance test, set the iterations.
            PerformanceTestCore test = new PerformanceTestCore();

            test.TestCount = Iterations;

            //  Run the performance test.
            test.RunTests();

            //  Set the result of the worker.
            e.Result = test;
        }